-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Doc]: add how to know available fonts... #21761
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll ping @aitikgupta here because I think he knows the font handling pretty well, and maybe could suggest an in-Matplotlib way of getting the right info (obviously we can't specify for all OS-es where the fonts are stored). |
For me, on WSL, the RC parameter
Maybe 'available font' means 'installed font'? |
Ah, OK, fair enough. Still the main point is that the list of possible fonts is not readily accessible. |
The available names are the |
Perfect, thanks! I actually think a little wrapper around that would help people (me). Even just |
Can I work on this as a good first issue over the weekend? :) The suggestion by @jklymak at the top level makes sense. Maybe another option to consider is Thanks |
@ojeda-e Please have at it! If you think there are a couple of reasonable ways to implement this, it would make it much easier to review if you include a discussion of why you picked the implementation you did in the comments on the PR. |
Thanks @tacaswell! |
I also don't know that it is a problem to have a low-level access and an upper-level access that wraps it. There are a few things that are nice to have near top level so folks don't have to try to remember the name of the library where they are implemented (the balance being everything can't be top level!) |
Even after installing a font it doesn't end up in Matplotlib's font cache and in turn, isn't available; one would need to rebuild it. There existed a way earlier (it wasn't a public function, but the top results of "matplotlib rebuild font cache" on Google still show this old website and SOs whose old answers mention I generally do this another way programmatically: from pathlib import Path
import matplotlib as mpl
import matplotlib.font_manager as fm
fm_path = Path(mpl.get_cachedir(), f"fontlist-v{fm.FontManager.__version__}.json")
fm = fm.FontManager()
fm.json_dump(fm, fm_path) |
So how do you "install" an "available" font? |
We "install" a font natively (a double click on a TTF/OTF file will bring up the installation) - the utility is provided by the OS, and the font is installed globally in the system. And once it is "installed", it can be made "available" for Matplotlib after rebuilding font cache. |
OK, so you are saying that just because the user does a system install of a font doesn't necessarily mean Matplotlib will consider it available, because it has to rebuild the cache first. |
yep! |
Documentation Link
https://matplotlib.org/stable/tutorials/text/text_props.html#default-font
Problem
In https://matplotlib.org/stable/tutorials/text/text_props.html#default-font we are told that we can use any "available fonts" for
fontfamily
. It would be nice if this tutorial, or another, indicated how to get that list of available fonts, and then specfically how to specify them infontfamily
. I tried a couple of things on stack overflow, butfont family
does not appear to accept full strings like "Times New Roman", so I assume I need to specify something more low level?Overall I find font handling still quite confusing, and it seems it requires deeper knwoledge than most users are going to have (or its explained somewhere that is not adequately cross linked).
Suggested improvement
No response
Matplotlib Version
main
The text was updated successfully, but these errors were encountered: