Skip to content

Fallback font doesn't work on windows? #5929

Closed

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

Activity

  1. jankatins commented on Jan 27, 2016

    @jankatins
    ContributorAuthor

    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...

  2. jankatins commented on Jan 27, 2016

    @jankatins
    ContributorAuthor

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

  3. jankatins commented on Jan 27, 2016

    @jankatins
    ContributorAuthor

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

  4. tacaswell commented on Jan 30, 2016

    @tacaswell
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions