Skip to content

Font weight inconsistencies #15170

Closed
Closed
@PatrickFeiring

Description

@PatrickFeiring

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:

Metadata

Metadata

Assignees

No one assigned

    Labels

    keepItems to be ignored by the “Stale” Github Actiontopic: text/fonts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions