-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MNT: Use __init__ parameters of font properties #28836
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
@@ -21,43 +21,36 @@ | |||
fig.text(0.1, 0.9, 'family', fontproperties=heading_font, **alignment) | |||
families = ['serif', 'sans-serif', 'cursive', 'fantasy', 'monospace'] | |||
for k, family in enumerate(families): | |||
font = FontProperties() | |||
font.set_family(family) | |||
font = FontProperties(family=family) |
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.
This broke with sans-serif
, probably because of this special case:
https://github.com/QuLogic/matplotlib/blob/0cdb45da1bfe0af330f87eeadcf633919cd26f80/lib/matplotlib/font_manager.py#L614-L620
It could probably be fixed by passing family=[family]
.
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.
Whoops. That's surprising and awkward. The __init__
parameter behaves differently compared to the set_family
method. 😢 But it's documented.
I believe FontProperties(pattern)
should be deprecated and we should instead add a FontProperties.from_pattern(pattern)
method. But that's for another PR (see #28837). For now, we have to go with the list.
Replace default initialization immediately followed by setting values by initialization with values, i.e. ``` # before: fp = FontProperties() fp.set_[something](val) # after fp = FontProperties([something]=val) ``` This is clearer and additionally helps with the possible transition of making FontProperties immutable, see matplotlib#22495.
6056a35
to
aefe7ad
Compare
Replace default initialization immediately followed by setting values by initialization with values, i.e.
This is clearer and additionally helps with the possible transition of making FontProperties immutable, see #22495.