.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/applications/plot_text.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_applications_plot_text.py: ========================= Render text onto an image ========================= Scikit-image currently doesn't feature a function that allows you to write text onto an image. However, there is a fairly easy workaround using scikit-image's optional dependency `matplotlib `_. .. GENERATED FROM PYTHON SOURCE LINES 12-27 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from skimage import data img = data.cat() fig = plt.figure() fig.figimage(img, resize=True) fig.text(0, 0.99, "I am stefan's cat.", fontsize=32, va="top") fig.canvas.draw() annotated_img = np.asarray(fig.canvas.renderer.buffer_rgba()) plt.close(fig) .. GENERATED FROM PYTHON SOURCE LINES 28-30 For the purpose of this example, we can also show the image; however, if one just wants to write onto the image, this step is not necessary. .. GENERATED FROM PYTHON SOURCE LINES 30-36 .. code-block:: Python fig, ax = plt.subplots() ax.imshow(annotated_img) ax.set_axis_off() ax.set_position([0, 0, 1, 1]) plt.show() .. image-sg:: /auto_examples/applications/images/sphx_glr_plot_text_001.png :alt: plot text :srcset: /auto_examples/applications/images/sphx_glr_plot_text_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.797 seconds) .. _sphx_glr_download_auto_examples_applications_plot_text.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/v0.23.2?filepath=notebooks/auto_examples/applications/plot_text.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_text.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_text.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_