{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n*************************\nText rendering With LaTeX\n*************************\n\nRendering text with LaTeX in Matplotlib.\n\nMatplotlib has the option to use LaTeX to manage all text layout. This\noption is available with the following backends:\n\n* Agg\n* PS\n* PDF\n\nThe LaTeX option is activated by setting ``text.usetex : True`` in your rc\nsettings. Text handling with matplotlib's LaTeX support is slower than\nmatplotlib's very capable :doc:`mathtext `, but is\nmore flexible, since different LaTeX packages (font packages, math packages,\netc.) can be used. The results can be striking, especially when you take care\nto use the same fonts in your figures as in the main document.\n\nMatplotlib's LaTeX support requires a working LaTeX_ installation, dvipng_\n(which may be included with your LaTeX installation), and Ghostscript_\n(GPL Ghostscript 8.60 or later is recommended). The executables for these\nexternal dependencies must all be located on your :envvar:`PATH`.\n\nThere are a couple of options to mention, which can be changed using\n:doc:`rc settings `. Here is an example\nmatplotlibrc file::\n\n font.family : serif\n font.serif : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman\n font.sans-serif : Helvetica, Avant Garde, Computer Modern Sans serif\n font.cursive : Zapf Chancery\n font.monospace : Courier, Computer Modern Typewriter\n\n text.usetex : true\n\nThe first valid font in each family is the one that will be loaded. If the\nfonts are not specified, the Computer Modern fonts are used by default. All of\nthe other fonts are Adobe fonts. Times and Palatino each have their own\naccompanying math fonts, while the other Adobe serif fonts make use of the\nComputer Modern math fonts. See the PSNFSS_ documentation for more details.\n\nTo use LaTeX and select Helvetica as the default font, without editing\nmatplotlibrc use::\n\n from matplotlib import rc\n rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})\n ## for Palatino and other serif fonts use:\n #rc('font',**{'family':'serif','serif':['Palatino']})\n rc('text', usetex=True)\n\nHere is the standard example, `tex_demo.py`:\n\n.. figure:: ../../gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png\n :target: ../../gallery/text_labels_and_annotations/tex_demo.html\n :align: center\n :scale: 50\n\n TeX Demo\n\nNote that display math mode (``$$ e=mc^2 $$``) is not supported, but adding the\ncommand ``\\displaystyle``, as in `tex_demo.py`, will produce the same\nresults.\n\n
Certain characters require special escaping in TeX, such as::\n\n # $ % & ~ _ ^ \\ { } \\( \\) \\[ \\]\n\n Therefore, these characters will behave differently depending on\n the rcParam ``text.usetex`` flag.