Skip to content

Commit 863aae9

Browse files
committed
DOC: Inline pgf userdemo examples
They are not too useful as examples, since they need to save `.pgf` files, which are not scraped nor exposed in any way from the generated docs.
1 parent c17197c commit 863aae9

File tree

4 files changed

+73
-104
lines changed

4 files changed

+73
-104
lines changed

galleries/examples/userdemo/pgf_fonts.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

galleries/examples/userdemo/pgf_preamble_sgskip.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

galleries/examples/userdemo/pgf_texsystem.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

galleries/users_explain/text/pgf.py

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
pdf.savefig(fig2)
9292
9393
94+
.. redirect-from:: /gallery/userdemo/pgf_fonts
95+
9496
Font specification
9597
==================
9698
@@ -107,9 +109,31 @@
107109
When saving to ``.pgf``, the font configuration Matplotlib used for the
108110
layout of the figure is included in the header of the text file.
109111
110-
.. literalinclude:: /gallery/userdemo/pgf_fonts.py
111-
:end-before: fig.savefig
112+
.. code-block:: python
113+
114+
import matplotlib.pyplot as plt
115+
116+
plt.rcParams.update({
117+
"font.family": "serif",
118+
# Use LaTeX default serif font.
119+
"font.serif": [],
120+
# Use specific cursive fonts.
121+
"font.cursive": ["Comic Neue", "Comic Sans MS"],
122+
})
123+
124+
fig, ax = plt.subplots(figsize=(4.5, 2.5))
112125
126+
ax.plot(range(5))
127+
128+
ax.text(0.5, 3., "serif")
129+
ax.text(0.5, 2., "monospace", family="monospace")
130+
ax.text(2.5, 2., "sans-serif", family="DejaVu Sans") # Use specific sans font.
131+
ax.text(2.5, 1., "comic", family="cursive")
132+
ax.set_xlabel("µ is not $\\mu$")
133+
134+
fig.tight_layout(pad=.5)
135+
136+
.. redirect-from:: /gallery/userdemo/pgf_preamble_sgskip
113137
114138
.. _pgf-preamble:
115139
@@ -122,16 +146,35 @@
122146
if you want to do the font configuration yourself instead of using the fonts
123147
specified in the rc parameters, make sure to disable :rc:`pgf.rcfonts`.
124148
125-
.. only:: html
149+
.. code-block:: python
150+
151+
import matplotlib as mpl
126152
127-
.. literalinclude:: /gallery/userdemo/pgf_preamble_sgskip.py
128-
:end-before: fig.savefig
153+
mpl.use("pgf")
154+
import matplotlib.pyplot as plt
155+
156+
plt.rcParams.update({
157+
"font.family": "serif", # use serif/main font for text elements
158+
"text.usetex": True, # use inline math for ticks
159+
"pgf.rcfonts": False, # don't setup fonts from rc parameters
160+
"pgf.preamble": "\n".join([
161+
r"\usepackage{url}", # load additional packages
162+
r"\usepackage{unicode-math}", # unicode math setup
163+
r"\setmainfont{DejaVu Serif}", # serif font via preamble
164+
])
165+
})
166+
167+
fig, ax = plt.subplots(figsize=(4.5, 2.5))
129168
130-
.. only:: latex
169+
ax.plot(range(5))
131170
132-
.. literalinclude:: /gallery/userdemo/pgf_preamble_sgskip.py
133-
:end-before: import matplotlib.pyplot as plt
171+
ax.set_xlabel("unicode text: я, ψ, €, ü")
172+
ax.set_ylabel(r"\url{https://matplotlib.org}")
173+
ax.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
134174
175+
fig.tight_layout(pad=.5)
176+
177+
.. redirect-from:: /gallery/userdemo/pgf_texsystem
135178
136179
.. _pgf-texsystem:
137180
@@ -143,9 +186,29 @@
143186
Please note that when selecting pdflatex, the fonts and Unicode handling must
144187
be configured in the preamble.
145188
146-
.. literalinclude:: /gallery/userdemo/pgf_texsystem.py
147-
:end-before: fig.savefig
189+
.. code-block:: python
190+
191+
import matplotlib.pyplot as plt
192+
193+
plt.rcParams.update({
194+
"pgf.texsystem": "pdflatex",
195+
"pgf.preamble": "\n".join([
196+
r"\usepackage[utf8x]{inputenc}",
197+
r"\usepackage[T1]{fontenc}",
198+
r"\usepackage{cmbright}",
199+
]),
200+
})
201+
202+
fig, ax = plt.subplots(figsize=(4.5, 2.5))
203+
204+
ax.plot(range(5))
205+
206+
ax.text(0.5, 3., "serif", family="serif")
207+
ax.text(0.5, 2., "monospace", family="monospace")
208+
ax.text(2.5, 2., "sans-serif", family="sans-serif")
209+
ax.set_xlabel(r"µ is not $\mu$")
148210
211+
fig.tight_layout(pad=.5)
149212
150213
.. _pgf-troubleshooting:
151214

0 commit comments

Comments
 (0)