-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
add documentation for reloading font cache #26453
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
Conversation
yourself if your new fonts cannot be found by Matplotlib. | ||
The cache can be rebuilt by using :func:`matplotlib.font_manager.load_fontmanager`:: | ||
import matplotlib as mpl | ||
mpl.font_manager.load_fontmanager(try_read_cache=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that this will actually work?
This will make a new font manager and return it to you, but it will not change the singleton that is used by the rest of the library or update the findfont
and get_font_names
held at the module level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My testing procedure for this was:
- add a new font to
mpl-data\fonts\ttf
- run a short plot with a
text
instance withfamily=new font
- see that the text doesn't update to the new font after multiple runs
- run the
font_manager.load_fontmanager
code - run the plot again
Now the text is now set to the new font and a new entry in the font cache is present. The findfont
and get_font_names
methods both return the new font.
I did notice however, that the before and after fontmanager instances were the same object with the same ID.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... ok, I do not understand why that works 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, question: are you running this all in the same process or each in its own Python process?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each in their own separate process.
Unfortunately I do not think it is this simple because we keep a singleton of this cache and then re-expose its methods at the module level. I think the steps here are:
An alternate path would be to update |
An alternate to my last comment is to explain why this does work as it looks like it creates a new |
Haven't read through the whole issue, but note that in the rebuild_if_missing branch at the end of findfont_cached, fontManager calls _load_fontmanager then replaces its |
That is a bit heavy handed, but makes sense (a However the way this is hidden behind a cache, we will only automatically discover the new font if it is there when we search for it. It might be worth also adding a public way to clear that cache. |
PR summary
Closes #24872. Adds documentation that describes the process of making newly added fonts available to the fontmanager.
load_fontmanager
method which can be used in place of the deprecatedmatplotlib.font_manager._rebuild()
method.Loading new fonts
section to thefonts-in-matplotlib
doc with an explanation of the methods of reloading the font cache, with example code.PR checklist