8000 Font weight inconsistencies · Issue #15170 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
8000

Font weight inconsistencies #15170

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

Open
PatrickFeiring opened this issue Sep 2, 2019 · 9 comments
Open

Font weight inconsistencies #15170

PatrickFeiring opened this issue Sep 2, 2019 · 9 comments
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/fonts

Comments

@PatrickFeiring
Copy link
Contributor

Bug report

Bug summary

There are some inconsistencies in the way that font weights are specified and set, and that in conjunction with the odd constructor logic in the FontProperties class leads to some buggy behaviour.

The rcParams validator converts all font weights to strings. This means that any integer or float value is converted to a string. When the font weight is supplied as a parameter, say plt.title('My title', fontweight=200), the value is not converted to a string.

This has a few implications:

  1. int(20.6) evaluates to 20, while int('20.6') raises an error. This means that a float supplied through rcParams, and subsequently converted to a string, will raise an error, while it will not raise an error when given as an argument to e.g. plt.title, it will only be floored.

  2. The FontProperties constructor parses a font config pattern if only the family is specified. When this is the case values not specified in the pattern are set directly from the rcParams, without using e.g. the set_weight method. Integer weights supplied as strings are handled in the set_weight method, but it will not be invoked in this case, leading to an error as it tries to use the value as it would use say 'normal'.

Matplotlib version

  • Operating system:
  • Matplotlib version: 3.1.1
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version:
  • Jupyter version (if applicable):
  • Other libraries:
@PatrickFeiring
Copy link
Contributor Author

I don't mind fixing this, but I am a little uncertain about how to handle things, also because the docs seems to use the word 'numeric', which means any number (including floats)? The code seems to only use integers. I see a few options:

  1. Allow floats.
  2. Use integers, but floor floats.
  3. Use integers, and disallow floats.

The first option is not in line with what seems to be common practice, to specify weights using integers(although I am not super familiar with different font specifications). The second option would probably not brake any code. The third is the strictest, and to me seems to match the intent the best. It could potentially break some code, but I doubt that many use float weights directly?

@anntzer
Copy link
Contributor
anntzer commented Sep 2, 2019

You may want to have a look at #10249 as well.

@pierre-haessig
Copy link
Contributor

I got hit with a font weight bug, but I'm not sure whether it relates to this one. On my Debian system with Matplotlib 3.1.1, I've an issue with the Lato font using:

plt.rcParams['font.sans-serif'] = ['Lato']

The selected font weight is very light, not the normal one despite the fact plt.rcParams['font.weight'] is set to 'normal'. Now, if I set it to 'medium' it's fine (but I still need to fix the title and axis weights...).

Is it related to the validation?

@anntzer
Copy link
Contributor
anntzer commented Oct 21, 2019

Likely this is related to #8550.
I have a fix but it'll take some time to turn it into a proper PR...

@pierre-haessig
Copy link
Contributor

A yes, thank you @anntzer for the correct pointer. Sorry for the noise.

@timhoffm
Copy link
Member

Duplicate #8550.

@anntzer
Copy link
Contributor
anntzer commented Oct 22, 2019

I think(?) the allowance or not of strings is a separate issue?

@timhoffm
Copy link
Member

Sorry, did not read the full history. The original posts by @PatrickFeiring are the relevant point here.

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 26, 2023
@anntzer anntzer added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action labels Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action topic: text/fonts
Projects
None yet
Development

No branches or pull requests

5 participants
0