Repository navigation
MNT: Use __init__ parameters of font properties - #28836
Merged
Merged
Conversation
QuLogic
reviewed
Sep 18, 2024
| for k, family in enumerate(families): | ||
| font = FontProperties() | ||
| font.set_family(family) | ||
| font = FontProperties(family=family) |
Member
There was a problem hiding this comment.
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].
Member
Author
There was a problem hiding this comment.
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.
timhoffm
force-pushed
the
FontProperties-init
branch
from
September 18, 2024 21:31
6056a35 to
aefe7ad
Compare
QuLogic
approved these changes
Sep 19, 2024
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Sep 19, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.