diff --git a/examples/userdemo/pgf_fonts.py b/examples/userdemo/pgf_fonts.py index 463d5c7e6887..1f9d49853bcf 100644 --- a/examples/userdemo/pgf_fonts.py +++ b/examples/userdemo/pgf_fonts.py @@ -8,18 +8,23 @@ import matplotlib.pyplot as plt plt.rcParams.update({ "font.family": "serif", - "font.serif": [], # use latex default serif font - "font.sans-serif": ["DejaVu Sans"], # use a specific sans-serif font + # Use LaTeX default serif font. + "font.serif": [], + # Use specific cursive fonts. + "font.cursive": ["Comic Neue", "Comic Sans MS"], }) -plt.figure(figsize=(4.5, 2.5)) -plt.plot(range(5)) -plt.text(0.5, 3., "serif") -plt.text(0.5, 2., "monospace", family="monospace") -plt.text(2.5, 2., "sans-serif", family="sans-serif") -plt.text(2.5, 1., "comic sans", family="Comic Sans MS") -plt.xlabel("µ is not $\\mu$") -plt.tight_layout(.5) +fig, ax = plt.subplots(figsize=(4.5, 2.5)) -plt.savefig("pgf_fonts.pdf") -plt.savefig("pgf_fonts.png") +ax.plot(range(5)) + +ax.text(0.5, 3., "serif") +ax.text(0.5, 2., "monospace", family="monospace") +ax.text(2.5, 2., "sans-serif", family="DejaVu Sans") # Use specific sans font. +ax.text(2.5, 1., "comic", family="cursive") +ax.set_xlabel("µ is not $\\mu$") + +fig.tight_layout(pad=.5) + +fig.savefig("pgf_fonts.pdf") +fig.savefig("pgf_fonts.png") diff --git a/examples/userdemo/pgf_preamble_sgskip.py b/examples/userdemo/pgf_preamble_sgskip.py index 99dcb3fa8da3..e16ee0f1bbf5 100644 --- a/examples/userdemo/pgf_preamble_sgskip.py +++ b/examples/userdemo/pgf_preamble_sgskip.py @@ -19,12 +19,15 @@ ]) }) -plt.figure(figsize=(4.5, 2.5)) -plt.plot(range(5)) -plt.xlabel("unicode text: я, ψ, €, ü") -plt.ylabel(r"\url{https://matplotlib.org}") -plt.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"]) -plt.tight_layout(.5) +fig, ax = plt.subplots(figsize=(4.5, 2.5)) -plt.savefig("pgf_preamble.pdf") -plt.savefig("pgf_preamble.png") +ax.plot(range(5)) + +ax.set_xlabel("unicode text: я, ψ, €, ü") +ax.set_ylabel(r"\url{https://matplotlib.org}") +ax.legend(["unicode math: $λ=∑_i^∞ μ_i^2$"]) + +fig.tight_layout(pad=.5) + +fig.savefig("pgf_preamble.pdf") +fig.savefig("pgf_preamble.png") diff --git a/examples/userdemo/pgf_texsystem.py b/examples/userdemo/pgf_texsystem.py index 622ba97ab740..dc44e8c12298 100644 --- a/examples/userdemo/pgf_texsystem.py +++ b/examples/userdemo/pgf_texsystem.py @@ -15,13 +15,16 @@ ]), }) -plt.figure(figsize=(4.5, 2.5)) -plt.plot(range(5)) -plt.text(0.5, 3., "serif", family="serif") -plt.text(0.5, 2., "monospace", family="monospace") -plt.text(2.5, 2., "sans-serif", family="sans-serif") -plt.xlabel(r"µ is not $\mu$") -plt.tight_layout(.5) +fig, ax = plt.subplots(figsize=(4.5, 2.5)) -plt.savefig("pgf_texsystem.pdf") -plt.savefig("pgf_texsystem.png") +ax.plot(range(5)) + +ax.text(0.5, 3., "serif", family="serif") +ax.text(0.5, 2., "monospace", family="monospace") +ax.text(2.5, 2., "sans-serif", family="sans-serif") +ax.set_xlabel(r"µ is not $\mu$") + +fig.tight_layout(pad=.5) + +fig.savefig("pgf_texsystem.pdf") +fig.savefig("pgf_texsystem.png") diff --git a/tutorials/text/pgf.py b/tutorials/text/pgf.py index eb9b8729da8a..43e7a9628973 100644 --- a/tutorials/text/pgf.py +++ b/tutorials/text/pgf.py @@ -97,7 +97,7 @@ layout of the figure is included in the header of the text file. .. literalinclude:: ../../gallery/userdemo/pgf_fonts.py - :end-before: plt.savefig + :end-before: fig.savefig .. _pgf-preamble: @@ -114,7 +114,7 @@ .. only:: html .. literalinclude:: ../../gallery/userdemo/pgf_preamble_sgskip.py - :end-before: plt.savefig + :end-before: fig.savefig .. only:: latex @@ -133,7 +133,7 @@ be configured in the preamble. .. literalinclude:: ../../gallery/userdemo/pgf_texsystem.py - :end-before: plt.savefig + :end-before: fig.savefig .. _pgf-troubleshooting: