()
| 28 | |
| 29 | @image_comparison(['font_styles'], style='mpl20') |
| 30 | def 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…