Skip to content

Fallback font doesn't work on windows? #5929

@jankatins

Description

@jankatins

This is a test failure matplotlib.tests.test_text.test_font_styles.test which results in an image without any text on it (found as part of #5922)

import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
from matplotlib import _get_data_path
data_path = _get_data_path()

from matplotlib.font_manager import FontProperties, findfont

normalFont = dict(
    family="sans-serif",
    style="normal",
    variant="normal",
    size=14)

prop = FontProperties(**normalFont)
path = findfont(prop, directory=data_path)
print(path)
fp = FontProperties(fname=path)

plt.figure()
ax = plt.subplot(1, 1, 1)

ax.annotate(
    "Normal Font",
    (0.1, 0.1),
    xycoords='axes fraction',
    fontproperties=fp)

ax.set_xticks([])
ax.set_yticks([])

This results in the following output:

C:\portabel\miniconda\envs\matplotlib_build\lib\site-packages\matplotlib-1.5.1+1064.g4f14fc8-py3.5-win-amd64.egg\matplotlib\mpl-data\fonts\ttf\STIXSizOneSymBol.ttf
c:\data\external\pydata\matplotlib\lib\matplotlib\font_manager.py:1314: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))
c:\data\external\pydata\matplotlib\lib\matplotlib\font_manager.py:1324: UserWarning: findfont: Could not match :family=DejaVu Sans:style=normal:variant=normal:weight=400:stretch=normal:size=14.0. Returning C:\portabel\miniconda\envs\matplotlib_build\lib\site-packages\matplotlib-1.5.1+1064.g4f14fc8-py3.5-win-amd64.egg\matplotlib\mpl-data\fonts\ttf\STIXSizOneSymBol.ttf
  UserWarning)
Out[14]: []

The produces image has not text on it :-(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions