Skip to content
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

Allow use of matplotlib relative font sizes #617

Closed
MarkWieczorek opened this issue Sep 18, 2020 · 3 comments
Closed

Allow use of matplotlib relative font sizes #617

MarkWieczorek opened this issue Sep 18, 2020 · 3 comments
Labels
wontfix This will not be worked on
Milestone

Comments

@MarkWieczorek
Copy link
Contributor

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.

@weiji14 weiji14 added the feature request New feature wanted label Sep 18, 2020
@weiji14
Copy link
Member

weiji14 commented Sep 18, 2020

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

Interesting idea. I'd like to hear from the rest of the team to see if this is within scope for pygmt, or best classified as an advanced feature. Yes we want pygmt to be easy to use, but @leouieda also mentioned before at #427 (comment) that we should avoid repeating the mistakes of matplotlib (namely having too many ways to do one thing, which goes agaist the Zen of Python - "There should be one-- and preferably only one --obvious way to do it.").

@seisman
Copy link
Member

seisman commented Nov 6, 2020

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.

It's more complicated, as GMT settings like FONT_TITLE set font type, size and color.

@seisman seisman added wontfix This will not be worked on and removed feature request New feature wanted labels Mar 28, 2024
@seisman
Copy link
Member

seisman commented Mar 28, 2024

In the GMT world, a font contains three attributes, size, fonttype and fill. An example of a valid font is 12p,Times-Roman,red.

To support relative font sizes like medium,Times-Roman,red, we have to parse every font-like arguments, and replace the relative font sizes with absolute values, which means a lot of coding work and is not the goal of PyGMT. I don't think we will implement it in PyGMT so I'm closing the issue.

Actually, this is an interesting idea that may be implemented in GMT instead. For reference, GMT's pen attribute has syntax like 2p,red,-, in which the pen width can be some special pen names like thin/thick/fat. I guess it's not that hard to have similar special/relative font sizes in GMT.

Please open a feature request on the GMT repository if you're still interested.

@seisman seisman closed this as completed Mar 28, 2024
@seisman seisman added this to the 0.12.0 milestone Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants