seaborn icon indicating copy to clipboard operation
seaborn copied to clipboard

Consider adding `figure.titlesize` and `figure.labelsize` rcmods

Open hguturu opened this issue 1 year ago • 4 comments

https://github.com/mwaskom/seaborn/blob/9087437ad28e872ff73e5ff10ce6c2e7d511d650/seaborn/rcmod.py#L386-L387

This would allow the figure suptitle to also scale up with plotting_context.

hguturu avatar Jul 14 '23 03:07 hguturu

This makes sense. I think these are relatively new rcParams?

mwaskom avatar Jul 18 '23 00:07 mwaskom

Not sure, but I think at least a few years. The blame on the classic style suggests at least the figure.titlesize option is going back 8 years - https://github.com/matplotlib/matplotlib/blame/2a4d905ff2e6493264190f07113dc7f2115a8c1c/lib/matplotlib/mpl-data/stylelib/classic.mplstyle#L308.

The figure.labelsize looks newer with a PR last year - https://github.com/matplotlib/matplotlib/pull/22566. These should be backward compatible and just ignored on older version?

hguturu avatar Jul 18 '23 01:07 hguturu

The RcParams object isn't a simple dictionary and does some parameter validation so if you try to modify figure.labelsize on the current minimally-supported seaborn version it raises

import matplotlib.pyplot as plt
plt.rcParams["figure.labelsize"] = 14
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/miniconda/envs/seaborn-pinned/lib/python3.8/site-packages/matplotlib/__init__.py:595, in RcParams.__setitem__(self, key, val)
    594 try:
--> 595     cval = self.validate[key](val)
    596 except ValueError as ve:

KeyError: 'figure.labelsize'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
Cell In[1], line 2
      1 import matplotlib.pyplot as plt
----> 2 plt.rcParams["figure.labelsize"] = 14

File ~/miniconda/envs/seaborn-pinned/lib/python3.8/site-packages/matplotlib/__init__.py:600, in RcParams.__setitem__(self, key, val)
    598     dict.__setitem__(self, key, cval)
    599 except KeyError as err:
--> 600     raise KeyError(
    601         f"{key} is not a valid rc parameter (see rcParams.keys() for "
    602         f"a list of valid parameters)") from err

KeyError: 'figure.labelsize is not a valid rc parameter (see rcParams.keys() for a list of valid parameters)'

But should be relatively easy to work around this on the seaborn side, either based on a version check or whether the parameter name exists in the RcParams.

mwaskom avatar Jul 18 '23 02:07 mwaskom

Looks like plt.rcParams has validate property https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/init.py#L664 that references https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/rcsetup.py#L878.

A safe check might be to see if figure.labelsize in plt.rcParams.validate?

hguturu avatar Jul 18 '23 04:07 hguturu