FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

MNT: Use __init__ parameters of font properties by timhoffm · Pull Request #28836 · matplotlib/matplotlib · GitHub

MNT: Use __init__ parameters of font properties - #28836

Merged
QuLogic merged 1 commit into
matplotlib:mainfrom
timhoffm:FontProperties-init
Sep 19, 2024
Merged

QuLogic merged 1 commit into
matplotlib:mainfrom
timhoffm:FontProperties-init

Conversation

Copy link
Copy Markdown
Member

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 #22495.

github-actions Bot added Documentation: examples files in galleries/examples Documentation: user guide files in galleries/users_explain or doc/users labels Sep 18, 2024
for k, family in enumerate(families):
font = FontProperties()
font.set_family(family)
font = FontProperties(family=family)

QuLogic Sep 18, 2024 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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].

timhoffm Sep 18, 2024 •
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.
QuLogic added this to the v3.9.3 milestone Sep 19, 2024
QuLogic merged commit 4b35874 into matplotlib:main Sep 19, 2024
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Sep 19, 2024
timhoffm deleted the FontProperties-init branch January 18, 2025 20:45
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

Labels

Documentation: examples files in galleries/examples Documentation: user guide files in galleries/users_explain or doc/users Maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL