

.. _sphx_glr_gallery_userdemo_pgf_preamble_sgskip.py:


============
Pgf Preamble
============




.. code-block:: python

    # -*- coding: utf-8 -*-
    from __future__ import (absolute_import, division, print_function,
                            unicode_literals)

    import six

    import matplotlib as mpl
    mpl.use("pgf")
    pgf_with_custom_preamble = {
        "font.family": "serif",  # use serif/main font for text elements
        "text.usetex": True,     # use inline math for ticks
        "pgf.rcfonts": False,    # don't setup fonts from rc parameters
        "pgf.preamble": [
             "\\usepackage{units}",          # load additional packages
             "\\usepackage{metalogo}",
             "\\usepackage{unicode-math}",   # unicode math setup
             r"\setmathfont{xits-math.otf}",
             r"\setmainfont{DejaVu Serif}",  # serif font via preamble
             ]
    }
    mpl.rcParams.update(pgf_with_custom_preamble)

    import matplotlib.pyplot as plt
    plt.figure(figsize=(4.5, 2.5))
    plt.plot(range(5))
    plt.xlabel("unicode text: я, ψ, €, ü, \\unitfrac[10]{°}{µm}")
    plt.ylabel("\\XeLaTeX")
    plt.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
    plt.tight_layout(.5)

    plt.savefig("pgf_preamble.pdf")
    plt.savefig("pgf_preamble.png")

**Total running time of the script:** ( 0 minutes  0.000 seconds)



.. only :: html

 .. container:: sphx-glr-footer


  .. container:: sphx-glr-download

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



  .. container:: sphx-glr-download

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


.. only:: html

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

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