Open Sans has pretty good coverage of the characters needed for plots, including the Greek alphabet, but it's missing, for example, a character that maps to the latex command $\phi$ (it's phi maps to $\varphi$). If you use the above configuration with textbox containing $\phi$, the system falls back to computer modern, in accordance with the fallback_to_cm rc parameter. It would be nice, however, to be able to fall back to a similar font for that character, preferable a sans serif font in a comparable weight.
This is already implemented for the default DejaVu Sans. It falls back to Stix Sans instead of CM to get a more uniform look. (In the DejaVuFonts class, the line
self.cm_fallback = StixSansFonts(*args, **kwargs)
sets this.)
In my example with Open Sans, I can get a better result by changing the line
in the UnicodeFonts class. That way, the fallback is a sans-serif font similar to the main font.
It seems like it would be fairly easy to allow users to set the fallback to one of the built-in fonts (cm, dejavuserif, dejavusans, stix, stixsans). It would be nice to also allow custom fallbacks (but then we might need to have a fallback for the fallback in case the custom choice lacks a needed character). In my example, you might want to set the main font in Open Sans, but the fallback to Noto Sans (a very similar Google font with more characters).
There are many high-quality free (and not free) fonts that would benefit from a fallback that's not computer modern. This feature would therefore increase the number of usable custom fontsets.
Implementation questions
I'd be happy to try implementing this myself, but I'm a new contributor, and I'm sure I'd mess some things up. Here are a few questions that come to mind:
Is this feature worth implementing?
It would probably require a change to the rc parameters. Is there a policy in place for doing so?
Like I mentioned above, allowing users to choose from one of the built-in fonts would be pretty straightforward. Is it worth also allowing custom fallbacks?
@geib7592 Sorry this fell through the cracks and didn't get a response for so long. There is a PR for this at #11644 which implements this for stix. How does that look for you? Do you have thoughts as to whether #11644 should also support other fallback families?
Great, I didn't realize this was being worked on. It seems like extending #16144 to also allow fallback to DejaVu Sans should be straightforward, and I think worthwhile for flexibility in using custom sans-serif fonts.
I just want to add one more point about why this PR is important, because so far it does not seem to be said in the other thread(s). Major scientific publishing companies like Nature and Science explicitly prefer Helvetica for the text of their figures. For Greek letters and symbols, they seem to use a similar weight serif font used in their main text. When I posted the original feature request, I was finding it surprisingly difficult to get results close to these professional standards, and I ended up having to tweak matplotlib internals to get what I was looking for. The PR as it stands really helps move in the right direction, and I hope to see more motion toward "industry standard" design principles in the future. I've thought a fair amount about this problem, so if the matplotlib folks are interested, I'd be happy to discuss and get more involved.
#11644 (sorry I typed the number wrong the first time) is getting revived at #16509; definitely please do share your thoughts on that PR as you likely have thought more about the problem than any of the current core devs :)
Activity
anntzer commented on Feb 13, 2020
@geib7592 Sorry this fell through the cracks and didn't get a response for so long. There is a PR for this at #11644 which implements this for stix. How does that look for you? Do you have thoughts as to whether #11644 should also support other fallback families?
geib7592 commented on Feb 14, 2020
Great, I didn't realize this was being worked on. It seems like extending #16144 to also allow fallback to DejaVu Sans should be straightforward, and I think worthwhile for flexibility in using custom sans-serif fonts.
I just want to add one more point about why this PR is important, because so far it does not seem to be said in the other thread(s). Major scientific publishing companies like Nature and Science explicitly prefer Helvetica for the text of their figures. For Greek letters and symbols, they seem to use a similar weight serif font used in their main text. When I posted the original feature request, I was finding it surprisingly difficult to get results close to these professional standards, and I ended up having to tweak matplotlib internals to get what I was looking for. The PR as it stands really helps move in the right direction, and I hope to see more motion toward "industry standard" design principles in the future. I've thought a fair amount about this problem, so if the matplotlib folks are interested, I'd be happy to discuss and get more involved.
Cheers!
anntzer commented on Feb 14, 2020
#11644 (sorry I typed the number wrong the first time) is getting revived at #16509; definitely please do share your thoughts on that PR as you likely have thought more about the problem than any of the current core devs :)
anntzer commented on Mar 10, 2020
Closed by #16509, AFAICT.