Skip to content

Unable to modify configurations after importing matplotlib in v1.72.0 #568

Description

@ToryDeng

In v1.72.0, the following lines of code cause an error:

import matplotlib.pyplot as plt
import ultraplot as uplt

print(uplt.__version__)
uplt.rc["figure.facecolor"] = "white"
1.72.0
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 5
      2 import ultraplot as uplt
      4 print(uplt.__version__)
----> 5 uplt.rc["figure.facecolor"] = "white"

File /usr/local/miniforge3/envs/svg/lib/python3.11/site-packages/ultraplot/__init__.py:235, in __getattr__(name)
    232     globals()[name] = basemap
    233     return basemap
--> 235 return _LOADER.get_attr(name, globals())

File /usr/local/miniforge3/envs/svg/lib/python3.11/site-packages/ultraplot/_lazy.py:179, in LazyLoader.get_attr(self, name, module_globals)
    177 if attr_map and name in attr_map:
    178     module_name, attr_name = attr_map[name]
--> 179     self._setup()
    180     module = self._import_module(module_name)
    181     value = getattr(module, attr_name) if attr_name else module

File /usr/local/miniforge3/envs/svg/lib/python3.11/site-packages/ultraplot/__init__.py:63, in _setup()
     61 success = False
     62 try:
---> 63     from .config import (
     64         rc,
     65         register_cmaps,
     66         register_colors,
     67         register_cycles,
     68         register_fonts,
     69     )
     70     from .internals import (
     71         fonts as _fonts,  # noqa: F401 - ensure mathtext override is active
     72     )
     73     from .internals import rcsetup, warnings

File /usr/local/miniforge3/envs/svg/lib/python3.11/site-packages/ultraplot/config.py:1850
   1846 rc_ultraplot = rcsetup._rc_ultraplot_default.copy()  # a validated rcParams-style dict
   1848 #: Instance of `Configurator`. This controls both `rc_matplotlib` and `rc_ultraplot`
   1849 #: settings. See the :ref:`configuration guide <ug_config>` for details.
-> 1850 rc = Configurator()
   1852 # Deprecated
   1853 RcConfigurator = warnings._rename_objs(
   1854     "0.8.0",
   1855     RcConfigurator=Configurator,
   1856 )

File /usr/local/miniforge3/envs/svg/lib/python3.11/site-packages/ultraplot/config.py:793, in Configurator.__init__(self, local, user, default, **kwargs)
    791 self._context = []
    792 self._setting_handlers = {}
--> 793 self._init(local=local, user=user, default=default, **kwargs)

File /usr/local/miniforge3/envs/svg/lib/python3.11/site-packages/ultraplot/config.py:897, in Configurator._init(self, local, user, default)
    895 if default:
    896     rc_matplotlib.update(_get_style_dict("original", filter=False))
--> 897     rc_matplotlib.update(rcsetup._rc_matplotlib_default)
    898     rc_ultraplot.update(rcsetup._rc_ultraplot_default)
    899     for key, value in rc_ultraplot.items():

File <frozen _collections_abc>:949, in update(self, other, **kwds)

File /usr/local/miniforge3/envs/svg/lib/python3.11/site-packages/matplotlib/__init__.py:774, in RcParams.__setitem__(self, key, val)
    772         cval = self.validate[key](val)
    773     except ValueError as ve:
--> 774         raise ValueError(f"Key {key}: {ve}") from None
    775     self._set(key, cval)
    776 except KeyError as err:

ValueError: Key axes.titlesize: med-large is not a valid font size. Valid font sizes are xx-small, x-small, small, medium, large, x-large, xx-large, smaller, larger.

However, in 1.70.0, they work fine:

import matplotlib.pyplot as plt
import ultraplot as uplt

print(uplt.__version__)
uplt.rc["figure.facecolor"] = "white"
1.70.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions