-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Comments
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:
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? |
You may want to have a look at #10249 as well. |
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:
The selected font weight is very light, not the normal one despite the fact Is it related to the validation? |
Likely this is related to #8550. |
A yes, thank you @anntzer for the correct pointer. Sorry for the noise. |
Duplicate #8550. |
I think(?) the allowance or not of strings is a separate issue? |
Sorry, did not read the full history. The original posts by @PatrickFeiring are the relevant point here. |
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! |
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:
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.
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
print(matplotlib.get_backend())
): MacOSXThe text was updated successfully, but these errors were encountered: