The selection criteria for finding fonts using the algorithm in matplotlib.font_manager.findfonts are incomplete. The problem arises with high-quality TTF fonts that have many different styles, for instance "Helvetica Neue", or "Lato". For instance, the "Thin" versions of these fonts are indistinguishable from the "Regular" versions by their font weight (both have e.g. a value of 400) such that the font that is returned by findfonts depends on the ordering of the list matplotlib.font_manager.fontManager.ttflist.
A workaround would be to simply uninstall the unwanted versions of the conflicting fonts from the system. Unfortunately, for the figures that I am trying to create, "Helvetica Neue" is mandatory and it is also an OSX system font, thus cannot be disabled.
I am unsure whether the fonts (for instance) "HelveticaNeue-Thin.ttf" and "HelveticaNeue.ttf" could be distinguished by adding another font metric to the Font class. If not, the proposed solution would be to allow selecting fonts in matplotlib.rcParams by their file name, e.g. setting mathtext.rm : "HelveticaNeue.ttf". This solution would require changing the fontconfig parser in matplotlib.fontconfig_pattern.py to allow filenames.
Code for reproduction
The result of the code below is system-dependent, even when exactly the same font files are installed, because of the ordering of matplotlib.font_manager.fontManager.ttflist.
This has been a recurring issue when adding new fonts to proplot -- I have to manually delete all of the "thin" files. Looks like the issue is in font_manager.ttfFontProperty. Here is where styles and weights are read:
If you're on linux (macos perhaps? if fontconfig is present) you can use https://github.com/anntzer/mplfccache to generate a more accurate font cache (asking fontconfig to list the font properties for you).
Activity
tacaswell commented on Jun 22, 2017
Related to #8551 #8607 #5250 #8550 #7931
This seems to have become a major problem recently.
lukelbd commented on Dec 18, 2019
This has been a recurring issue when adding new fonts to proplot -- I have to manually delete all of the "thin" files. Looks like the issue is in font_manager.ttfFontProperty. Here is where styles and weights are read:
matplotlib/lib/matplotlib/font_manager.py
Lines 358 to 438 in 5fb9709
What can we do to detect the 'thin' property? Also is 'thin' a style or a weight?
anntzer commented on Dec 18, 2019
If you're on linux (macos perhaps? if fontconfig is present) you can use https://github.com/anntzer/mplfccache to generate a more accurate font cache (asking fontconfig to list the font properties for you).
I have translated into Python the actual algorithm used by fontconfig to determine font properties at https://github.com/anntzer/freetypybind/blob/master/lib/freetypybind/query_face.py (using my own freetype binding but that shouldn't matter much); someone "just" needs to PR that into Matplotlib...
anntzer commented on May 28, 2020
Mostly closed by #16203.