

.. _sphx_glr_users_explain_text:

.. redirect-from:: /tutorials/text

.. _tutorials-text:

Text
----

Matplotlib has extensive text support, including support for
mathematical expressions, TrueType support for raster and
vector outputs, newline separated text with arbitrary
rotations, and Unicode support. These tutorials cover
the basics of working with text in Matplotlib.

For even more information see the :ref:`examples page <text_labels_and_annotations>`.



.. raw:: html

    <div class="sphx-glr-thumbnails">

.. thumbnail-parent-div-open

.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Matplotlib has extensive text support, including support for mathematical expressions, truetype support for raster and vector outputs, newline separated text with arbitrary rotations, and Unicode support.">

.. only:: html

  .. image:: /users/explain/text/images/thumb/sphx_glr_text_intro_thumb.png
    :alt:

  :ref:`sphx_glr_users_explain_text_text_intro.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Text in Matplotlib</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Controlling properties of text and its layout with Matplotlib.">

.. only:: html

  .. image:: /users/explain/text/images/thumb/sphx_glr_text_props_thumb.png
    :alt:

  :ref:`sphx_glr_users_explain_text_text_props.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Text properties and layout</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Annotations are graphical elements, often pieces of text, that explain, add context to, or otherwise highlight some portion of the visualized data. annotate supports a number of coordinate systems for flexibly positioning data and annotations relative to each other and a variety of options of for styling the text. Axes.annotate also provides an optional arrow from the text to the data and this arrow can be styled in various ways. text can also be used for simple text annotation, but does not provide as much flexibility in positioning and styling as annotate.">

.. only:: html

  .. image:: /users/explain/text/images/thumb/sphx_glr_annotations_thumb.png
    :alt:

  :ref:`sphx_glr_users_explain_text_annotations.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Annotations</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Matplotlib needs fonts to work with its text engine, some of which are shipped alongside the installation.  The default font is DejaVu Sans which covers most European writing systems. However, users can configure the default fonts, and provide their own custom fonts.  See Customizing text properties &lt;text_props&gt; for details and font-nonlatin in particular for glyphs not supported by DejaVu Sans.">

.. only:: html

  .. image:: /users/explain/text/images/thumb/sphx_glr_fonts_thumb.png
    :alt:

  :ref:`sphx_glr_users_explain_text_fonts.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Fonts in Matplotlib</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Matplotlib implements a lightweight TeX expression parser and layout engine and Mathtext is the subset of Tex markup that this engine supports. Note that Matplotlib can also render all text directly using TeX if text.usetex is True; see usetex for more details.   Mathtext support is available if text.usetex is False.">

.. only:: html

  .. image:: /users/explain/text/images/thumb/sphx_glr_mathtext_thumb.png
    :alt:

  :ref:`sphx_glr_users_explain_text_mathtext.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Writing mathematical expressions</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Using the pgf backend, Matplotlib can export figures as pgf drawing commands that can be processed with pdflatex, xelatex or lualatex. XeLaTeX and LuaLaTeX have full Unicode support and can use any font that is installed in the operating system, making use of advanced typographic features of OpenType, AAT and Graphite. Pgf pictures created by plt.savefig(&#x27;figure.pgf&#x27;) can be embedded as raw commands in LaTeX documents. Figures can also be directly compiled and saved to PDF with plt.savefig(&#x27;figure.pdf&#x27;) by switching the backend ::">

.. only:: html

  .. image:: /users/explain/text/images/thumb/sphx_glr_pgf_thumb.png
    :alt:

  :ref:`sphx_glr_users_explain_text_pgf.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Text rendering with XeLaTeX/LuaLaTeX via the pgf backend</div>
    </div>


.. raw:: html

    <div class="sphx-glr-thumbcontainer" tooltip="Matplotlib can use LaTeX to render text.  This is activated by setting text.usetex : True in your rcParams, or by setting the usetex property to True on individual Text objects.  Text handling through LaTeX is slower than Matplotlib&#x27;s very capable mathtext, but is more flexible, since different LaTeX packages (font packages, math packages, etc.) can be used. The results can be striking, especially when you take care to use the same fonts in your figures as in the main document.">

.. only:: html

  .. image:: /users/explain/text/images/thumb/sphx_glr_usetex_thumb.png
    :alt:

  :ref:`sphx_glr_users_explain_text_usetex.py`

.. raw:: html

      <div class="sphx-glr-thumbnail-title">Text rendering with LaTeX</div>
    </div>


.. thumbnail-parent-div-close

.. raw:: html

    </div>


.. toctree::
   :hidden:

   /users/explain/text/text_intro
   /users/explain/text/text_props
   /users/explain/text/annotations
   /users/explain/text/fonts
   /users/explain/text/mathtext
   /users/explain/text/pgf
   /users/explain/text/usetex

