proplot-dev / proplot

🎨 A succinct matplotlib wrapper for making beautiful, publication-quality graphics
https://proplot.readthedocs.io
MIT License
1.11k stars 102 forks source link

Bug: pplt.rc.load does not work properly #333

Closed syrte closed 2 years ago

syrte commented 2 years ago

Description

pplt.rc.load does not work properly. I found the problem when I was playing with ~/.proplotrc. The same problem appears as in the following example.

Steps to reproduce

I save a rc file as follows

import proplot as pplt

pplt.rc['font.size'] = 10
pplt.rc['axes.labelsize'] = 'med-large'
pplt.rc.save('proplotrc', comment=True, backup=False, description=True)
pplt.rc['font.size'],pplt.rc['axes.labelsize'], pplt.rc['label.size']

It prints (10.0, 'med-large', 'med-large')

The file is indeed updated with the lines

# Changed settings
label.size:     med-large
axes.labelsize: med-large
font.size:      10.0

Then I restart the session and load the same file as follows

import proplot as pplt
pplt.rc.load('proplotrc')
pplt.rc['font.size'],pplt.rc['axes.labelsize'], pplt.rc['label.size']

It prints (10.000000000000002, 'medium', 'medium').

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)here. 3.4.3 0.9.5.post259

syrte commented 2 years ago

The problem can be located to pplt.rc._load_file.

syrte commented 2 years ago

It seems that a lot of things get updated when rc loads the fontsize from file, which can overwrite the setting of labelsize. If the file stores the keys in a different order:

font.size:      10.0
label.size:     med-large
axes.labelsize: med-large

Then the labelsize setting is ensured to use the file value.


I will be satisfied with the above workaround for now. If I got time, I may dig a bit more.

lukelbd commented 2 years ago

Thanks for the report. Note the reason font.size also updates all those other font settings is related to #212. When fontsize is passed to ax.format() we have to re-apply the font scalings like 'medium' and 'large' now that they are derived from a different base font.size. I guess something about the order of application is messing this up.

lukelbd commented 2 years ago

This is fixed by 6ea48d5. The issue was that in the proplotrc file, font.size came after label.size. The internal implementation of _load_file caused the font.size setting to overwrite your label.size with the default value.

Now your example

import proplot as pplt
pplt.rc.load('proplotrc')
pplt.rc['font.size'],pplt.rc['axes.labelsize'], pplt.rc['label.size']

correctly prints (10.000000000000002, 'med-large', 'med-large').

syrte commented 2 years ago

Many thanks for the quick fix!!!