MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_font_styles

Function test_font_styles

lib/matplotlib/tests/test_text.py:30–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

28
29@image_comparison(['font_styles'], style='mpl20')
30def test_font_styles():
31
32 def find_matplotlib_font(**kw):
33 prop = FontProperties(**kw)
34 path = findfont(prop, directory=mpl.get_data_path())
35 return FontProperties(fname=path)
36
37 from matplotlib.font_manager import FontProperties, findfont
38 warnings.filterwarnings(
39 'ignore',
40 r"findfont: Font family \[u?'Foo'\] not found. Falling back to .",
41 UserWarning,
42 module='matplotlib.font_manager')
43
44 fig, ax = plt.subplots()
45
46 normal_font = find_matplotlib_font(
47 family="sans-serif",
48 style="normal",
49 variant="normal",
50 size=14)
51 a = ax.annotate(
52 "Normal Font",
53 (0.1, 0.1),
54 xycoords='axes fraction',
55 fontproperties=normal_font)
56 assert a.get_fontname() == 'DejaVu Sans'
57 assert a.get_fontstyle() == 'normal'
58 assert a.get_fontvariant() == 'normal'
59 assert a.get_weight() == 'normal'
60 assert a.get_stretch() == 'normal'
61
62 bold_font = find_matplotlib_font(
63 family="Foo",
64 style="normal",
65 variant="normal",
66 weight="bold",
67 stretch=500,
68 size=14)
69 ax.annotate(
70 "Bold Font",
71 (0.1, 0.2),
72 xycoords='axes fraction',
73 fontproperties=bold_font)
74
75 bold_italic_font = find_matplotlib_font(
76 family="sans serif",
77 style="italic",
78 variant="normal",
79 weight=750,
80 stretch=500,
81 size=14)
82 ax.annotate(
83 "Bold Italic Font",
84 (0.1, 0.3),
85 xycoords='axes fraction',
86 fontproperties=bold_italic_font)
87

Callers

nothing calls this directly

Calls 10

find_matplotlib_fontFunction · 0.85
annotateMethod · 0.80
get_fontstyleMethod · 0.80
get_fontvariantMethod · 0.80
set_xticksMethod · 0.80
set_yticksMethod · 0.80
subplotsMethod · 0.45
get_fontnameMethod · 0.45
get_weightMethod · 0.45
get_stretchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…