Skip to content

Allow use of matplotlib relative font sizes #617

Closed
@MarkWieczorek

Description

@MarkWieczorek

Matplotlib defines a set of relative font sizes, such as "medium" and "large". Unfortunately, matplotlib mixes absolute and relative font sizes in the rcParams dictionary. When using pygmt, I often take the font sizes from my existing rcParams dictionary, and then pass them to pygmt.config to customize my plots like this:

pygmt.config(FONT_TITLE=mpl.rcParams['axes.titlesize'])

If the font size it somthing like "medium", pygmt.config doesn't know what to do and generates a warning.

One way around this would be for pygmt.config to convert the relative font sizes (str) to absolute font sizes (float). I found this method that does just this:

In [1]: mpl.font_manager.FontProperties(size='large').get_size_in_points()
Out[1]: 12.0

Another way would be to use this predifined dictionary:

In [2]: mpl.font_manager.font_scalings
Out[2]:
{'xx-small': 0.579,
 'x-small': 0.694,
 'small': 0.833,
 'medium': 1.0,
 'large': 1.2,
 'x-large': 1.44,
 'xx-large': 1.728,
 'larger': 1.2,
 'smaller': 0.833,
 None: 1.0}

The easiest thing to do would be to test if the font size is a string, and if True, use one of the above methods to convert it to points.

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions