
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "gallery/text_labels_and_annotations/rainbow_text.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. meta::
        :keywords: codex

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_gallery_text_labels_and_annotations_rainbow_text.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_text_labels_and_annotations_rainbow_text.py:


==================================================
Concatenate text objects with different properties
==================================================

The example strings together several Text objects with different properties
(e.g., color or font), positioning each one after the other.  The first Text
is created directly using `~.Axes.text`; all subsequent ones are created with
`~.Axes.annotate`, which allows positioning the Text's lower left corner at the
lower right corner (``xy=(1, 0)``) of the previous one (``xycoords=text``).

.. GENERATED FROM PYTHON SOURCE LINES 12-32



.. image-sg:: /gallery/text_labels_and_annotations/images/sphx_glr_rainbow_text_001.png
   :alt: rainbow text
   :srcset: /gallery/text_labels_and_annotations/images/sphx_glr_rainbow_text_001.png, /gallery/text_labels_and_annotations/images/sphx_glr_rainbow_text_001_2_00x.png 2.00x
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt

    plt.rcParams["font.size"] = 20
    ax = plt.figure().add_subplot(xticks=[], yticks=[])

    # The first word, created with text().
    text = ax.text(.1, .5, "Matplotlib", color="red")
    # Subsequent words, positioned with annotate(), relative to the preceding one.
    text = ax.annotate(
        " says,", xycoords=text, xy=(1, 0), verticalalignment="bottom",
        color="gold", weight="bold")  # custom properties
    text = ax.annotate(
        " hello", xycoords=text, xy=(1, 0), verticalalignment="bottom",
        color="green", style="italic")  # custom properties
    text = ax.annotate(
        " world!", xycoords=text, xy=(1, 0), verticalalignment="bottom",
        color="blue", family="serif")  # custom properties

    plt.show()


.. _sphx_glr_download_gallery_text_labels_and_annotations_rainbow_text.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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