Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback font doesn't work on windows? #5929

Closed
jankatins opened this issue Jan 27, 2016 · 4 comments
Closed

Fallback font doesn't work on windows? #5929

jankatins opened this issue Jan 27, 2016 · 4 comments

Comments

@jankatins
Copy link
Contributor

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 :-(

@jankatins
Copy link
Contributor Author

Ok, I think I found the problem: in

os.path.commonprefix([font.fname, directory]) != directory):

os.path.commonprefix([font.fname, directory]) != directory):

font.fname pointed to a old installation in my conda env but directory to the source directory which I also installed in that conda env via python setup.py develop. Let's see what happens when I remove that old package and reinstall the develop version...

@jankatins
Copy link
Contributor Author

Ok, I learned something new: matplotlib has a font cache and you should delete that thing from time to time...

@jankatins
Copy link
Contributor Author

And the tests pass... sorry for the noise...

@tacaswell
Copy link
Member

One of @mdboom 's mid-term goals in to kill our font cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants