Repository navigation
Closed
Labels
Description
Bug report
Bug summary
I cannot use many of my system fonts inside matplotlib. If I specify a font family as an explicit argument, e.g.,
import matplotlib.pyplot as plt
plt.figure()
plt.figtext(0.5, 0.5, 'Sample text', ha='center', va='center', family='DejaVu Sans Condensed', size=10)I get this message:
findfont: Font family ['DejaVu Sans Condensed'] not found. Falling back to DejaVu Sans.However, DejaVu Sans Condensed is definitely there on the system:
$ fc-list | grep DejaVu | grep Condensed
DejaVu Serif,DejaVu Serif Condensed:style=Condensed,Book
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold Italic,Bold Italic
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Bold,Bold
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Oblique,Oblique
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold Oblique,Bold Oblique
DejaVu Sans,DejaVu Sans Condensed:style=Condensed,Book
DejaVu Sans,DejaVu Sans Condensed:style=Condensed Bold,Bold
DejaVu Serif,DejaVu Serif Condensed:style=Condensed Italic,Italic
Same for some other fonts such as 'Nimbus Sans L'.
More (related) info
When I delete ~/.cache/matplotlib and start ipython, I get the following message:
$ ipython --profile=python3 --pylab
Python 3.7.4 (default, Aug 26 2019, 13:24:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.7.0 -- An enhanced Interactive Python. Type '?' for help.
IPython profile: python3
fc-list: unrecognized option '--format=%{file}\n'
usage: fc-list [-vV?] [--verbose] [--version] [--help] [pattern] {element ...}
List fonts matching [pattern]
-v, --verbose display status information while busy
-V, --version display font config version and exit
-?, --help display this help and exit
Using matplotlib backend: TkAgg
The error message from fc-list makes me think that matplotlib cannot build its font cache.
Further, I tried probing matplotlib.font_manager directly.
import matplotlib.font_manager
In [5]: [s for s in matplotlib.font_manager.findSystemFonts() if 'DejaVuSansCondensed' in s]
Out[5]:
['/usr/share/fonts/truetype/DejaVuSansCondensed-Bold.ttf',
'/usr/share/fonts/truetype/DejaVuSansCondensed-Oblique.ttf',
'/usr/share/fonts/truetype/DejaVuSansCondensed.ttf',
'/usr/share/fonts/truetype/DejaVuSansCondensed-BoldOblique.ttf']However, if I try to get a list of fontconfig fonts, it returns empty:
In [6]: flist = matplotlib.font_manager.get_fontconfig_fonts()
In [7]: flist
Out[7]: []Expected outcome
I should be able to use basic system fonts in matplotlib.
Matplotlib version
- Operating system: SuSE Linux 64 bit
- Matplotlib version: 3.1.1 (installed with
pip install matplotlib) - Matplotlib backend (
print(matplotlib.get_backend())): TkAgg - Python version: 3.7.4
- Jupyter version (if applicable): N/A
Activity
anntzer commentedon Nov 7, 2019
What does running
fc-list --format='%{file}\n'at the terminal return for you?What is your version of fontconfig?
It looks like fc-list --format was implemented in fontconfig 10y ago (https://gitlab.freedesktop.org/fontconfig/fontconfig/commit/0c93b91db0cdf7c5e901477c266b45c8baeadd00) so I'm comfortable saying we only support fontconfig versions that are more recent than that (which means >=2.7), given that this only affects autodetection of system fonts.
AgilentGCMS commentedon Nov 7, 2019
Yikes, my fontconfig version is 2.6, and
fc-list --format='%{file}\n'returns an invalid argument error. Given that this is on a high performance computing cluster over which I have little control, is there a workaround? Perhaps by modifying the matplotlib code?anntzer commentedon Nov 7, 2019
You can explicitly pass font paths: https://matplotlib.org/gallery/text_labels_and_annotations/font_file.html#sphx-glr-gallery-text-labels-and-annotations-font-file-py
The reason for using --format=%{file} is essentially discussed at #2433 (diff).