Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ed47b8b

Browse files
committed
Update usetex_fonteffects example.
- Use Figure.text() / Figure.suptitle() instead of adding text to an Axes and then going through the bother of setting the axes limits and then hiding the axes. - Explicitly pass usetex=True to the sole text() call instead of using rc(). - Show the figure, demonstrating that things work in agg as well, instead of creating a pdf file that then needs to be cleaned out of the source tree (but mention that saving to pdf works too). - fstringify.
1 parent dc1f0d9 commit ed47b8b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

examples/text_labels_and_annotations/usetex_fonteffects.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,25 @@
44
==================
55
66
This script demonstrates that font effects specified in your pdftex.map
7-
are now supported in pdf usetex.
7+
are now supported in usetex mode.
88
"""
99

10-
import matplotlib
1110
import matplotlib.pyplot as plt
12-
matplotlib.rc('text', usetex=True)
1311

1412

1513
def setfont(font):
16-
return r'\font\a %s at 14pt\a ' % font
14+
return rf'\font\a {font} at 14pt\a '
1715

1816

17+
fig = plt.figure()
1918
for y, font, text in zip(range(5),
2019
['ptmr8r', 'ptmri8r', 'ptmro8r',
2120
'ptmr8rn', 'ptmrr8re'],
2221
['Nimbus Roman No9 L ' + x for x in
2322
['', 'Italics (real italics for comparison)',
2423
'(slanted)', '(condensed)', '(extended)']]):
25-
plt.text(0, y, setfont(font) + text)
24+
fig.text(.1, (y + 1) / 6, setfont(font) + text, usetex=True)
2625

27-
plt.ylim(-1, 5)
28-
plt.xlim(-0.2, 0.6)
29-
plt.setp(plt.gca(), frame_on=False, xticks=(), yticks=())
30-
plt.title('Usetex font effects')
31-
plt.savefig('usetex_fonteffects.pdf')
26+
fig.suptitle('Usetex font effects')
27+
# Would also work if saving to pdf.
28+
plt.show()

0 commit comments

Comments
 (0)