-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
write addfont example #24866
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
write addfont example #24866
Conversation
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.
thanks for tackling this - sorry I didn't get back to you, but I don't know much about fonts either.
lib/matplotlib/font_manager.py
Outdated
for font_file in font_files: | ||
font_manager.fontManager.addfont(font_file) |
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.
needs indent
lib/matplotlib/font_manager.py
Outdated
|
||
`addfont` must be called on the global `fontManager` instance:: | ||
|
||
import matplotlib.pyplot as plt |
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.
so I think since this is API reference, you can drop the plotting example
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.
No worries. I added the plot because i thought you wanted to show how it works in the example.
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 can honestly go either way when it's a parameter docstring so now I'm leaning again towards keeping it so folks know how to test if they did it correctly 😅
or a combination of both. | ||
(see :doc:`font tutorial </tutorials/text/text_props>`) | ||
|
||
See `~.font_manager.FontManager.addfont` for adding a font family from a file. |
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.
That's a weird one. I only meant to add line 12
I continue to be extremely skeptical that we want to document this or "here is how to do something we think is a really bad idea". If we really do want to document this (which again I have doubts about), it should go in the comment at the top of https://matplotlib.org/stable/api/font_manager_api.html#module-matplotlib.font_manager or in the docstring for https://matplotlib.org/stable/api/font_manager_api.html#matplotlib.font_manager.fontManager |
@tacaswell Do you mean you think addfont() should not have been public API? See discussion at #15068. |
Not fair to quote past me against my current me! My thinking has moved more towards "we should not roll our own font discovery" given that we have gotten pushed that way (and there are system APIs for doing it) on windows and osx. Saying "put the fonts where your system expects" and then rebuilding our cache seems like both the correct and easiest (for us) path forward. That said, On a bit more consideration, that I think the information that needs to be clear:
but we should not suggest things (abusing pypi to distribute fonts (which we ourselves do)) that we think are a bad idea! |
I'd pull that out of a comment into docs since it seems to be a summary of the module, but I think adding this info to the top makes sense. Maybe w/ a nice big note section w/ all the caveats. I was thinking something in the style of the animation or color docs. |
Maybe I should put a bookmark in this issue for the time being. |
@saranti. We discussed this at the weekly meeting. I don't personally understand all the ins and outs, so I won't suggest wording, but the consensus was that the I believe some of the technical details that have to get across are that |
Would it be a good idea to add the longer explanation with an example in the text tutorials, just below |
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.
Nit about wording but solves my documentation concerns.
lib/matplotlib/font_manager.py
Outdated
However, fonts added with the `FontManager.addfont` method will not persist | ||
in the cache and hence will need to be called at every process. This method |
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.
However, fonts added with the `FontManager.addfont` method will not persist | |
in the cache and hence will need to be called at every process. This method | |
Fonts added with the `FontManager.addfont` method will not persist | |
in the cache; therefore *addfont* will need to be called every time matplotlib is imported. This method |
not quite sure, but something a little more explicit
Thanks @saranti - I took the liberty of squash merging.... |
PR Summary
Fixes #24419. Adds an example to the addfont function in the fontManager reference docs.
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst