We're trying to fix the font in our MPL scripts to avoid PNG and PDF images changing depending on who produced it (Linux / Mac machines, different MPL versions).
So our idea was to find one font that everyone has and set that font.
How can I find out if I have 'Bitstream Vera Sans' (or some other font) available in my MPL install?
I tried this and got a RunTimeError.
Is this a bug or am I doing it wrong?
In [1]: %paste
import matplotlib.font_manager
flist = matplotlib.font_manager.get_fontconfig_fonts()
names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
print('Bitstream Vera Sans' in names)
## -- End pasted text --
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-1-d6f6752cbc94> in <module>()
1 import matplotlib.font_manager
2 flist = matplotlib.font_manager.get_fontconfig_fonts()
----> 3 names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
4 print('Bitstream Vera Sans' in names)
<ipython-input-1-d6f6752cbc94> in <listcomp>(.0)
1 import matplotlib.font_manager
2 flist = matplotlib.font_manager.get_fontconfig_fonts()
----> 3 names = [matplotlib.font_manager.FontProperties(fname=fname).get_name() for fname in flist]
4 print('Bitstream Vera Sans' in names)
/opt/local/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/matplotlib/font_manager.py in get_name(self)
735 properties.
736 """
--> 737 return ft2font.FT2Font(findfont(self)).family_name
738
739 def get_style(self):
RuntimeError: In FT2Font: Could not set the fontsize
Python 3.5 and MPL 1.5.3 from Macports on macOS.
We're trying to fix the font in our MPL scripts to avoid PNG and PDF images changing depending on who produced it (Linux / Mac machines, different MPL versions).
So our idea was to find one font that everyone has and set that font.
How can I find out if I have 'Bitstream Vera Sans' (or some other font) available in my MPL install?
I tried this and got a RunTimeError.
Is this a bug or am I doing it wrong?
Python 3.5 and MPL 1.5.3 from Macports on macOS.