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

    Click :ref:`here <sphx_glr_download_gallery_text_labels_and_annotations_mathtext_asarray.py>` to download the full example code
.. rst-class:: sphx-glr-example-title

.. _sphx_glr_gallery_text_labels_and_annotations_mathtext_asarray.py:


===============================
A mathtext image as numpy array
===============================

Make images from LaTeX strings.



.. code-block:: python


    import matplotlib.mathtext as mathtext
    import matplotlib.pyplot as plt
    import matplotlib
    matplotlib.rc('image', origin='upper')

    parser = mathtext.MathTextParser("Bitmap")
    parser.to_png('test2.png',
                  r'$\left[\left\lfloor\frac{5}{\frac{\left(3\right)}{4}} '
                  r'y\right)\right]$', color='green', fontsize=14, dpi=100)

    rgba1, depth1 = parser.to_rgba(
        r'IQ: $\sigma_i=15$', color='blue', fontsize=20, dpi=200)
    rgba2, depth2 = parser.to_rgba(
        r'some other string', color='red', fontsize=20, dpi=200)

    fig = plt.figure()
    fig.figimage(rgba1, 100, 100)
    fig.figimage(rgba2, 100, 300)

    plt.show()




.. image:: /gallery/text_labels_and_annotations/images/sphx_glr_mathtext_asarray_001.png
    :class: sphx-glr-single-img




------------

References
""""""""""

The use of the following functions, methods, classes and modules is shown
in this example:



.. code-block:: python


    import matplotlib
    matplotlib.mathtext
    matplotlib.mathtext.MathTextParser
    matplotlib.mathtext.MathTextParser.to_png
    matplotlib.mathtext.MathTextParser.to_rgba
    matplotlib.figure.Figure.figimage







.. _sphx_glr_download_gallery_text_labels_and_annotations_mathtext_asarray.py:


.. only :: html

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



  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

    Keywords: matplotlib code example, codex, python plot, pyplot
    `Gallery generated by Sphinx-Gallery
    <https://sphinx-gallery.readthedocs.io>`_
