Skip to content

Commit 763a0fc

Browse files
committed
rename and add further examples
1 parent 0465692 commit 763a0fc

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

examples/text_labels_and_annotations/font_family_rc.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,48 @@
2626
2727
.. redirect-from:: /examples/font_family_rc_sgskip
2828
29-
First example:
29+
# First example, chooses default sans-serif font:
3030
"""
3131

3232
import matplotlib.pyplot as plt
3333

34-
plt.rcParams["font.family"] = "sans-serif"
35-
plt.rcParams["font.sans-serif"] = ["Tahoma"]
3634

37-
fig, ax = plt.subplots(figsize=(6, 1), facecolor="#eefade")
38-
ax.text(0.01, 0.2, "Hello World! 01", size=40)
39-
ax.axis("off")
40-
plt.show()
35+
def print_text(text):
36+
fig, ax = plt.subplots(figsize=(6, 1), facecolor="#eefade")
37+
ax.text(0.01, 0.2, text, size=40)
38+
ax.axis("off")
39+
plt.show()
4140

4241

42+
plt.rcParams["font.family"] = "sans-serif"
43+
print_text("Hello World! 01")
4344
#############################################################################
4445
#
4546
# Second example:
4647

48+
plt.rcParams["font.family"] = "sans-serif"
49+
plt.rcParams["font.sans-serif"] = "Tahoma"
50+
print_text("Hello World! 02")
51+
52+
#############################################################################
53+
#
54+
# Third example:
55+
56+
plt.rcParams["font.family"] = "sans-serif"
57+
plt.rcParams["font.sans-serif"] = "Lucida Grande"
58+
print_text("Hello World! 03")
59+
60+
#############################################################################
61+
#
62+
# Fourth example, chooses default monospace font:
63+
64+
plt.rcParams["font.family"] = "monospace"
65+
print_text("Hello World! 04")
66+
67+
#############################################################################
68+
#
69+
# Fifth example:
4770

4871
plt.rcParams["font.family"] = "monospace"
49-
# plt.rcParams['font.monospace'] = ['Computer Modern Typewriter'] # this line gives an error currently, therefore the
50-
# question: How can one access the fonts from https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/mpl-data/matplotlibrc#L273
51-
# the correct way?
52-
fig, ax = plt.subplots(figsize=(6, 1), facecolor="#eefade")
53-
ax.text(0.01, 0.2, "Hello World! 01", size=40)
54-
ax.axis("off")
55-
plt.show()
72+
plt.rcParams["font.monospace"] = "Menlo"
73+
print_text("Hello World! 05")

examples/text_labels_and_annotations/font_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Matplotlib.
1313
1414
For a more flexible solution, see
15-
:doc:`/gallery/text_labels_and_annotations/font_family_rc_sgskip` and
15+
:doc:`/gallery/text_labels_and_annotations/font_family_rc` and
1616
:doc:`/gallery/text_labels_and_annotations/fonts_demo`.
1717
"""
1818

0 commit comments

Comments
 (0)