|
26 | 26 |
|
27 | 27 | .. redirect-from:: /examples/font_family_rc_sgskip |
28 | 28 |
|
29 | | -First example: |
| 29 | +# First example, chooses default sans-serif font: |
30 | 30 | """ |
31 | 31 |
|
32 | 32 | import matplotlib.pyplot as plt |
33 | 33 |
|
34 | | -plt.rcParams["font.family"] = "sans-serif" |
35 | | -plt.rcParams["font.sans-serif"] = ["Tahoma"] |
36 | 34 |
|
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() |
41 | 40 |
|
42 | 41 |
|
| 42 | +plt.rcParams["font.family"] = "sans-serif" |
| 43 | +print_text("Hello World! 01") |
43 | 44 | ############################################################################# |
44 | 45 | # |
45 | 46 | # Second example: |
46 | 47 |
|
| 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: |
47 | 70 |
|
48 | 71 | 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") |
0 commit comments