With a lot of the modern fonts containing exotic font weights like “Thin” or “Ultra bold”, matplotlib will sometimes pick the wrong font weight because it assumes that any font weight that it doesn’t recognize is either normal (400) or bold (700), even though there is a “Regular” available. Ultimately which one matplotlib picks seems to be actually kind of random, probably depending on the order in which the fonts appear in the font cache.
I imagine we could add “Thin” and some others into the list, but I don’t think this solves the fundamental problem that fonts with unrecognized weights are presumed “Regular”/“Bold” and do not have lower precedence than fonts that are definitely “Regular”/“Bold”.
TL;DR: It would be nice to have a more robust way to detect font weights and handle unknown font weights.
This is a bit of "wish" but I think it would nice to have the option to specify the subfamily explicitly, in case the subfamily is really exotic. So I should be able to pass e.g. font="Fira Sans Four" and get the Four subfamily. (Either parse the subfamily from the user-provided string, or have a second attribute font_subfamily, which is arguably more principled.)
Can you even do that with the font-config tools? That seems like a difficult parsing problem as the space is used to both in the family name (which I think in 'Fire Sans') and to separate the sub-family.
There is a PR from @mdboom to replace our home-grown font selection with font-config around...
https://github.com/anntzer/mplfccache should allow you to regenerate the font cache using the metadata provided by fontconfig (obviously, this depends on fontconfig utilities being available in the $PATH).
Activity
Rufflewind commented on Jun 26, 2017
This is a bit of "wish" but I think it would nice to have the option to specify the subfamily explicitly, in case the subfamily is really exotic. So I should be able to pass e.g. font="Fira Sans Four" and get the Four subfamily. (Either parse the subfamily from the user-provided string, or have a second attribute font_subfamily, which is arguably more principled.)
(@tacaswell)
tacaswell commented on Jun 26, 2017
Can you even do that with the font-config tools? That seems like a difficult parsing problem as the space is used to both in the family name (which I think in 'Fire Sans') and to separate the sub-family.
There is a PR from @mdboom to replace our home-grown font selection with font-config around...
Rufflewind commented on Jun 26, 2017
Looks like font-config uses a colon:
(I'm actually surprised that font-config even recognizes subfamily)
anntzer commented on Dec 6, 2018
https://github.com/anntzer/mplfccache should allow you to regenerate the font cache using the metadata provided by fontconfig (obviously, this depends on fontconfig utilities being available in the $PATH).
I also have a Python reimplementation of (most of) fontconfig's logic (translated from source) in https://github.com/anntzer/freetypybind/blob/master/lib/freetypybind/query_face.py#L499, just needs some packaging effort...
anntzer commented on May 28, 2020
#16203 fixes most of this. I think the "direct access to subfamily request" is tracked by #4822.