|
5 | 5 |
|
6 | 6 | How to typeset text with the ``pgf`` backend in Matplotlib.
|
7 | 7 |
|
8 |
| -Using the ``pgf`` backend,matplotlib can export figures as pgf drawing |
| 8 | +Using the ``pgf`` backend,Matplotlib can export figures as pgf drawing |
9 | 9 | commands that can be processed with pdflatex, xelatex or lualatex. XeLaTeX and
|
10 |
| -LuaLaTeX have fullunicode support and can use any font that is installed in |
| 10 | +LuaLaTeX have fullUnicode support and can use any font that is installed in |
11 | 11 | the operating system, making use of advanced typographic features of OpenType,
|
12 | 12 | AAT and Graphite. Pgf pictures created by ``plt.savefig('figure.pgf')``
|
13 | 13 | can be embedded as raw commands in LaTeX documents. Figures can also be
|
14 |
| -directly compiled and saved to PDF with ``plt.savefig('figure.pdf')`` by either |
15 |
| -switching to the backend |
16 |
| -
|
17 |
| -.. code-block:: python |
| 14 | +directly compiled and saved to PDF with ``plt.savefig('figure.pdf')`` by |
| 15 | +switching the backend :: |
18 | 16 |
|
19 | 17 | matplotlib.use('pgf')
|
20 | 18 |
|
21 |
| -orregistering it for handling pdf output |
| 19 | +orby explicitly requesting the use of the ``pgf`` backend :: |
22 | 20 |
|
23 |
| -.. code-block:: python |
| 21 | + plt.savefig('figure.pdf', backend='pgf') |
| 22 | +
|
| 23 | +or by registering it for handling pdf output :: |
24 | 24 |
|
25 | 25 | from matplotlib.backends.backend_pgf import FigureCanvasPgf
|
26 | 26 | matplotlib.backend_bases.register_backend('pdf', FigureCanvasPgf)
|
27 | 27 |
|
28 |
| -Thesecond method allows you to keep using regular interactive backends and to |
| 28 | +Thelast method allows you to keep using regular interactive backends and to |
29 | 29 | save xelatex, lualatex or pdflatex compiled PDF files from the graphical user
|
30 | 30 | interface.
|
31 | 31 |
|
|
35 | 35 | figures can optionally be saved to PNG images as well. The executables
|
36 | 36 | for all applications must be located on your :envvar:`PATH`.
|
37 | 37 |
|
38 |
| -Rc parameters that control the behavior of the pgf backend: |
| 38 | +`.rcParams` that control the behavior of the pgf backend: |
39 | 39 |
|
40 | 40 | ================= =====================================================
|
41 | 41 | Parameter Documentation
|
|
61 | 61 | Multi-Page PDF Files
|
62 | 62 | ====================
|
63 | 63 |
|
64 |
| -The pgf backend also supports multipage pdf files using ``PdfPages`` |
| 64 | +The pgf backend also supports multipage pdf files using |
| 65 | +`~.backend_pgf.PdfPages` |
65 | 66 |
|
66 | 67 | .. code-block:: python
|
67 | 68 |
|
|
83 | 84 | ==================
|
84 | 85 |
|
85 | 86 | The fonts used for obtaining the size of text elements or when compiling
|
86 |
| -figures to PDF are usually defined in thematplotlib rc parameters. You can |
87 |
| -also use theLaTeX default Computer Modern fonts by clearing the lists for |
88 |
| -``font.serif``, ``font.sans-serif`` or``font.monospace``. Please note that the |
89 |
| -glyphcoverage of these fonts is very limited. If you want to keep the Computer |
90 |
| -Modern font face but require extendedunicode support, consider installing the |
| 87 | +figures to PDF are usually defined in the`.rcParams`. You can also use the |
| 88 | +LaTeX default Computer Modern fonts by clearing the lists for :rc:`font.serif`, |
| 89 | +:rc:`font.sans-serif` or:rc:`font.monospace`. Please note that the glyph |
| 90 | +coverage of these fonts is very limited. If you want to keep the Computer |
| 91 | +Modern font face but require extendedUnicode support, consider installing the |
91 | 92 | `Computer Modern Unicode`__ fonts *CMU Serif*, *CMU Sans Serif*, etc.
|
92 | 93 |
|
93 | 94 | __ https://sourceforge.net/projects/cm-unicode/
|
94 | 95 |
|
95 |
| -When saving to ``.pgf``, the font configurationmatplotlib used for the |
| 96 | +When saving to ``.pgf``, the font configurationMatplotlib used for the |
96 | 97 | layout of the figure is included in the header of the text file.
|
97 | 98 |
|
98 | 99 | .. literalinclude:: ../../gallery/userdemo/pgf_fonts.py
|
|
105 | 106 | ===============
|
106 | 107 |
|
107 | 108 | Full customization is possible by adding your own commands to the preamble.
|
108 |
| -Usethe ``pgf.preamble`` parameter if you want to configure the math fonts, |
| 109 | +Use:rc:`pgf.preamble` if you want to configure the math fonts, |
109 | 110 | using ``unicode-math`` for example, or for loading additional packages. Also,
|
110 | 111 | if you want to do the font configuration yourself instead of using the fonts
|
111 |
| -specified in the rc parameters, make sure to disable``pgf.rcfonts``. |
| 112 | +specified in the rc parameters, make sure to disable:rc:`pgf.rcfonts`. |
112 | 113 |
|
113 | 114 | .. only:: html
|
114 | 115 |
|
|
126 | 127 | Choosing the TeX system
|
127 | 128 | =======================
|
128 | 129 |
|
129 |
| -The TeX system to be used bymatplotlib is chosen bythe ``pgf.texsystem`` |
130 |
| -parameter.Possible values are ``'xelatex'`` (default), ``'lualatex'`` and |
131 |
| -``'pdflatex'``.Please note that when selecting pdflatex the fonts and |
132 |
| -unicode handling mustbe configured in the preamble. |
| 130 | +The TeX system to be used byMatplotlib is chosen by:rc:`pgf.texsystem`. |
| 131 | +Possible values are ``'xelatex'`` (default), ``'lualatex'`` and ``'pdflatex'``. |
| 132 | +Please note that when selecting pdflatex, the fonts and Unicode handling must |
| 133 | +be configured in the preamble. |
133 | 134 |
|
134 | 135 | .. literalinclude:: ../../gallery/userdemo/pgf_texsystem.py
|
135 | 136 | :end-before: plt.savefig
|
|
162 | 163 | that your LaTeX syntax is valid and that you are using raw strings
|
163 | 164 | if necessary to avoid unintended escape sequences.
|
164 | 165 |
|
165 |
| -*The ``pgf.preamble`` rc setting provides lots of flexibility, and lots of |
| 166 | +*:rc:`pgf.preamble` provides lots of flexibility, and lots of |
166 | 167 | ways to cause problems. When experiencing problems, try to minimalize or
|
167 | 168 | disable the custom preamble.
|
168 | 169 |
|
|
176 | 177 |
|
177 | 178 | __ http://tex.stackexchange.com/questions/43642
|
178 | 179 |
|
179 |
| -* If the font configuration used bymatplotlib differs from the font setting |
| 180 | +* If the font configuration used byMatplotlib differs from the font setting |
180 | 181 | in yout LaTeX document, the alignment of text elements in imported figures
|
181 | 182 | may be off. Check the header of your ``.pgf`` file if you are unsure about
|
182 |
| - the fontsmatplotlib used for the layout. |
| 183 | + the fontsMatplotlib used for the layout. |
183 | 184 |
|
184 | 185 | * Vector images and hence ``.pgf`` files can become bloated if there are a lot
|
185 | 186 | of objects in the graph. This can be the case for image processing or very
|
|