
.. 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 <sphx_glr_download_auto_examples_applications_plot_text.py>`
        to download the full example code.

.. 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
<https://matplotlib.org/>`_.

.. GENERATED FROM PYTHON SOURCE LINES 12-27

.. code-block:: Python


    import matplotlib.pyplot as plt
    import numpy as np
    import skimage as ski

    img = ski.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.921 seconds)


.. _sphx_glr_download_auto_examples_applications_plot_text.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_text.ipynb <plot_text.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_text.py <plot_text.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_text.zip <plot_text.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
