Skip to content

Commit 648bd37

Browse files
committed
DOC: Convert pgf examples to OO style.
1 parent 0bdc2ab commit 648bd37

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

examples/userdemo/pgf_fonts.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
"font.sans-serif": ["DejaVu Sans"], # use a specific sans-serif font
1313
})
1414

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)
15+
fig, ax = plt.subplots(figsize=(4.5, 2.5))
2316

24-
plt.savefig("pgf_fonts.pdf")
25-
plt.savefig("pgf_fonts.png")
17+
ax.plot(range(5))
18+
19+
ax.text(0.5, 3., "serif")
20+
ax.text(0.5, 2., "monospace", family="monospace")
21+
ax.text(2.5, 2., "sans-serif", family="sans-serif")
22+
ax.text(2.5, 1., "comic sans", family="Comic Sans MS")
23+
ax.set_xlabel("µ is not $\\mu$")
24+
25+
fig.tight_layout(pad=.5)
26+
27+
fig.savefig("pgf_fonts.pdf")
28+
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)