8000 Merge pull request #18685 from QuLogic/pgf-examples · matplotlib/matplotlib@efa0ece · GitHub
[go: up one dir, main page]

Skip to content

Commit efa0ece

Browse files
authored
Merge pull request #18685 from QuLogic/pgf-examples
Cleanup pgf examples
2 parents 3e9efe7 + 1b6d0dd commit efa0ece

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

examples/userdemo/pgf_fonts.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,23 @@
88
import matplotlib.pyplot as plt
99
plt.rcParams.update({
1010
"font.family": "serif",
11-
"font.serif": [], # use latex default serif font
12-
"font.sans-serif": ["DejaVu Sans"], # use a specific sans-serif font
11+
# Use LaTeX default serif font.
12+
"font.serif": [],
13+
# Use specific cursive fonts.
14+
"font.cursive": ["Comic Neue", "Comic Sans MS"],
1315
})
1416

15-
plt.figure(figsize=(4.5, 2.5))
16-
plt.plot(range(5))
17-
plt.text(0.5, 3., "serif")
18-
plt.text(0.5, 2., "monospace", family="monospace")
19-
plt.text(2.5, 2., "sans-serif", family="sans-serif")
20-
plt.text(2.5, 1., "comic sans", family="Comic Sans MS")
21-
plt.xlabel("µ is not $\\mu$")
22-
plt.tight_layout(.5)
17+
fig, ax = plt.subplots(figsize=(4.5, 2.5))
2318

24-
plt.savefig("pgf_fonts.pdf")
25-
plt.savefig("pgf_fonts.png")
19+
ax.plot(range(5))
20+
21+
ax.text(0.5, 3., "serif")
22+
ax.text(0.5, 2., "monospace", family="monospace")
23+
ax.text(2.5, 2., "sans-serif", family="DejaVu Sans") # Use specific sans font.
24+
ax.text(2.5, 1., "comic", family="cursive")
25+
ax.set_xlabel("µ is not $\\mu$")
26+
27+
fig.tight_layout(pad=.5)
28+
29+
fig.savefig("pgf_fonts.pdf")
30+
fig.savefig("pgf_fonts.png")

examples/userdemo/pgf_preamble_sgskip.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
])
2020
})
2121

22-
plt.figure(figsize=(4.5, 2.5))
23-
plt.plot(range(5))
24-
plt.xlabel("unicode text: я, ψ, €, ü")
25-
plt.ylabel(r"\url{https://matplotlib.org}")
26-
plt.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
27-
plt.tight_layout(.5)
22+
fig, ax = plt.subplots(figsize=(4.5, 2.5))
2823

29-
plt.savefig("pgf_preamble.pdf")
30-
plt.savefig("pgf_preamble.png")
24+
ax.plot(range(5))
25+
26+
ax.set_xlabel("unicode text: я, ψ, €, ü")
27+
ax.set_ylabel(r"\url{https://matplotlib.org}")
28+
ax.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"])
29+
30+
fig.tight_layout(pad=.5)
31+
32+
fig.savefig("pgf_preamble.pdf")
33+
fig.savefig("pgf_preamble.png")

examples/userdemo/pgf_texsystem.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
]),
1616
})
1717

18-
plt.figure(figsize=(4.5, 2.5))
19-
plt.plot(range(5))
20-
plt.text(0.5, 3., "serif", family="serif")
21-
plt.text(0.5, 2., "monospace", family="monospace")
22-
plt.text(2.5, 2., "sans-serif", family="sans-serif")
23-
plt.xlabel(r"µ is not $\mu$")
24-
plt.tight_layout(.5)
18+
fig, ax = plt.subplots(figsize=(4.5, 2.5))
2519

26-
plt.savefig("pgf_texsystem.pdf")
27-
plt.savefig("pgf_texsystem.png")
20+
ax.plot(range(5))
21+
22+
ax.text(0.5, 3., "serif", family="serif")
23+
ax.text(0.5, 2., "monospace", family="monospace")
24+
ax.text(2.5, 2., "sans-serif", family="sans-serif")
25+
ax.set_xlabel(r"µ is not $\mu$")
26+
27+
fig.tight_layout(pad=.5)
28+
29+
fig.savefig("pgf_texsystem.pdf")
30+
fig.savefig("pgf_texsystem.png")

tutorials/text/pgf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
layout of the figure is included in the header of the text file.
9898
9999
.. literalinclude:: ../../gallery/userdemo/pgf_fonts.py
100-
:end-before: plt.savefig
100+
:end-before: fig.savefig
101101
102102
103103
.. _pgf-preamble:
@@ -114,7 +114,7 @@
114114
.. only:: html
115115
116116
.. literalinclude:: ../../gallery/userdemo/pgf_preamble_sgskip.py
117-
:end-before: plt.savefig
117+
:end-before: fig.savefig
118118
119119
.. only:: latex
120120
@@ -133,7 +133,7 @@
133133
be configured in the preamble.
134134
135135
.. literalinclude:: ../../gallery/userdemo/pgf_texsystem.py
136-
:end-before: plt.savefig
136+
:end-before: fig.savefig
137137
138138
139139
.. _pgf-troubleshooting:

0 commit comments

Comments
 (0)
0