|
19 | 19 | itself (only LaTeX is supported). The executables for these external
|
20 | 20 | dependencies must all be located on your :envvar:`PATH`.
|
21 | 21 |
|
22 |
| -There are a couple of options to mention, which can be changed using |
23 |
| -:doc:`rc settings </tutorials/introductory/customizing>`. Here is an example |
24 |
| -matplotlibrc file:: |
25 |
| -
|
26 |
| - font.family : serif |
27 |
| - font.serif : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman |
28 |
| - font.sans-serif : Helvetica, Avant Garde, Computer Modern Sans Serif |
29 |
| - font.cursive : Zapf Chancery |
30 |
| - font.monospace : Courier, Computer Modern Typewriter |
31 |
| -
|
32 |
| - text.usetex : true |
33 |
| -
|
34 |
| -The first valid font in each family is the one that will be loaded. If the |
35 |
| -fonts are not specified, the Computer Modern fonts are used by default. All of |
36 |
| -the other fonts are Adobe fonts. Times and Palatino each have their own |
37 |
| -accompanying math fonts, while the other Adobe serif fonts make use of the |
38 |
| -Computer Modern math fonts. See the PSNFSS_ documentation for more details. |
39 |
| -
|
40 |
| -To use LaTeX and select Helvetica as the default font, without editing |
41 |
| -matplotlibrc use:: |
42 |
| -
|
43 |
| - import matplotlib.pyplot as plt |
44 |
| - plt.rcParams.update({ |
45 |
| - "text.usetex": True, |
46 |
| - "font.family": "sans-serif", |
47 |
| - "font.sans-serif": ["Helvetica"]}) |
48 |
| - # for Palatino and other serif fonts use: |
49 |
| - plt.rcParams.update({ |
50 |
| - "text.usetex": True, |
51 |
| - "font.family": "serif", |
52 |
| - "font.serif": ["Palatino"], |
53 |
| - }) |
54 |
| - # It's also possible to use the reduced notation by directly setting font.family: |
55 |
| - plt.rcParams.update({ |
56 |
| - "text.usetex": True, |
57 |
| - "font.family": "Helvetica" |
58 |
| - }) |
59 |
| -
|
60 |
| -Currently, the supported fonts are: |
61 |
| -
|
62 |
| -================= ============================================================ |
63 |
| -family fonts |
64 |
| -================= ============================================================ |
65 |
| -``'serif'`` ``'New Century Schoolbook'``, ``'Bookman'``, ``'Times'``, |
66 |
| - ``'Palatino'``, ``'Charter'``, ``'Computer Modern Roman'`` |
67 |
| -
|
68 |
| -``'sans-serif'`` ``'Helvetica'``, ``'Avant Garde'``, ``'Computer Modern |
69 |
| - Serif'`` |
70 |
| -
|
71 |
| -``'cursive'`` ``'Zapf Chancery'`` |
72 |
| -
|
73 |
| -``'monospace'`` ``'Courier'``, ``'Computer Modern Typewriter'`` |
74 |
| -================= ============================================================ |
| 22 | +Only a small number of font families (defined by the PSNFSS_ scheme) are |
| 23 | +supported. They are listed here, with the corresponding LaTeX font selection |
| 24 | +commands and LaTeX packages, which are automatically used. |
| 25 | +
|
| 26 | +=========================== ================================================= |
| 27 | +generic family fonts |
| 28 | +=========================== ================================================= |
| 29 | +serif (``\rmfamily``) Computer Modern Roman, Palatino (``mathpazo``), |
| 30 | + Times (``mathptmx``), Bookman (``bookman``), |
| 31 | + New Century Schoolbook (``newcent``), |
| 32 | + Charter (``charter``) |
| 33 | +
|
| 34 | +sans-serif (``\sffamily``) Computer Modern Serif, Helvetica (``helvet``), |
| 35 | + Avant Garde (``avant``) |
| 36 | +
|
| 37 | +cursive (``\rmfamily``) Zapf Chancery (``chancery``) |
| 38 | +
|
| 39 | +monospace (``\ttfamily``) Computer Modern Typewriter, Courier (``courier``) |
| 40 | +=========================== ================================================= |
| 41 | +
|
| 42 | +The default font family (which does not require loading any LaTeX package) is |
| 43 | +Computer Modern. All other families are Adobe fonts. Times and Palatino each |
| 44 | +have their own accompanying math fonts, while the other Adobe serif fonts make |
| 45 | +use of the Computer Modern math fonts. |
| 46 | +
|
| 47 | +To enable LaTeX and select a font, use e.g.:: |
| 48 | +
|
| 49 | + plt.rcParams.update({ |
| 50 | + "text.usetex": True, |
| 51 | + "font.family": "Helvetica" |
| 52 | + }) |
| 53 | +
|
| 54 | +or equivalently, set your :doc:`matplotlibrc |
| 55 | +</tutorials/introductory/customizing>` to:: |
| 56 | +
|
| 57 | + text.usetex : true |
| 58 | + font.family : Helvetica |
| 59 | +
|
| 60 | +It is also possible to instead set ``font.family`` to one of the generic family |
| 61 | +names and then configure the corresponding generic family; e.g.:: |
| 62 | +
|
| 63 | + plt.rcParams.update({ |
| 64 | + "text.usetex": True, |
| 65 | + "font.family": "sans-serif", |
| 66 | + "font.sans-serif": "Helvetica", |
| 67 | + }) |
| 68 | +
|
| 69 | +(this was the required approach until Matplotlib 3.5). |
75 | 70 |
|
76 | 71 | Here is the standard example,
|
77 | 72 | :doc:`/gallery/text_labels_and_annotations/tex_demo`:
|
|
86 | 81 | Non-ASCII characters (e.g. the degree sign in the y-label above) are supported
|
87 | 82 | to the extent that they are supported by inputenc_.
|
88 | 83 |
|
| 84 | +.. note:: |
| 85 | + For consistency with the non-usetex case, Matplotlib special-cases newlines, |
| 86 | + so that single-newlines yield linebreaks (rather than being interpreted as |
| 87 | + whitespace in standard LaTeX). |
| 88 | +
|
| 89 | + Matplotlib uses the underscore_ package so that underscores (``_``) are |
| 90 | + printed "as-is" in text mode (rather than causing an error as in standard |
| 91 | + LaTeX). Underscores still introduce subscripts in math mode. |
| 92 | +
|
89 | 93 | .. note::
|
90 | 94 | Certain characters require special escaping in TeX, such as::
|
91 | 95 |
|
92 |
| - # $ % & ~ _ ^ \ { } \( \) \[ \] |
| 96 | + # $ % & ~ ^ \ { } \( \) \[ \] |
93 | 97 |
|
94 | 98 | Therefore, these characters will behave differently depending on
|
95 |
| - :rc:`text.usetex`. |
| 99 | + :rc:`text.usetex`. As noted above, underscores (``_``) do not require |
| 100 | + escaping outside of math mode. |
96 | 101 |
|
97 | 102 | PostScript options
|
98 | 103 | ==================
|
|
164 | 169 | .. _Poppler: https://poppler.freedesktop.org/
|
165 | 170 | .. _PSNFSS: http://www.ctan.org/tex-archive/macros/latex/required/psnfss/psnfss2e.pdf
|
166 | 171 | .. _PSfrag: https://ctan.org/pkg/psfrag
|
| 172 | +.. _underscore: https://ctan.org/pkg/underscore |
167 | 173 | .. _Xpdf: http://www.xpdfreader.com/
|
168 | 174 | """
|
0 commit comments