Open tacaswell opened 1 year ago
If you are doing some redesign, can I suggest some thought into different types of rcParams and differentiating when they can be set? We use rcParams as both defaults for various style things, but also for configuration of pretty crucial things like the backend, or things like a default layout manager or unit converters. Having some way to differentiate those roles (or locking them out), and clarifying when things can be set (before startup, before figure creation, before artist creation, before the next draw) would be really helpful.
I personally use style sheets, but otherwise avoid setting anything in my matplotlibrc except the default backend because I don't find it is very portable.
I see @timhoffm had this idea a while ago: https://github.com/matplotlib/matplotlib/pull/12577 [edit: well, a related idea]
provide a bug-for-bug compatible read/write accessor that mimics the current rcParams.
can be realized either by making the new config class API compatible with rcParams. Alternatively, we can have a new mpl.config
with whatever API we like and turn rcParams
into a proxy that only translates to mpl.config
and does not hold any config state anymore. I assume either way will be hard if you plan to continue supporting unbound dict methods operating on these objects).
BTW, the new object should be available as mpl.config
. rcParams
will only stay for backward compatibility.
I have some older thoughts on the "new configuration class" topic at https://gist.github.com/timhoffm/0a4d3d2b01115d77f930ceaadc4523ac. May need some consolidation, but should be helpful for some additional ideas.
What if the config class has two containers (dicts?) - one for the default that is set (a la rcParamsDefault
) and the other that contains "user added" options? This way, the burden of checking whether a user updated a value or not lies only on the existence of the key in the second dictionary and not on the value of that particular key. This would also satisfy all the requirements mentioned in the first comment about the behaviour of the configuration class by checking keys in the two.
https://docs.python.org/3/library/collections.html
Stdlib ChainMap is almost exactly that idea
Starting to think about what it would like to replace rcParams. It has served us well, but reflect what you could do with Python ~20 years ago (looks like it started as just a plain dictionary and picked up validation in 2007). Given the changes to Python, our experiences working with the current rcparams, and an eye towards near-term explosion of the number of things we may want to parameterize after the NASA work, I think it is worth having a discussion about what a green-field implementation of a global configuration signleton class would look like.
This line of thinking is triggered by a question via private communications about how to use a style file that only applies to rcParams that have not already been updated. In principle, you could do this by looking at rcParamsDefault (or some other baseline), but you would still have no way of telling if a value was intentionally set to a value that just happened to be the default value or not.
I would propose the following set of requirements:
setdefault
style filtering (please set this key only if it has never been updated)Other things we should consider:
__getattr__
rather than__getitem__
runtime extension of known keys
I want to keep this discussion independent of how we fabricate the singleton configuration.
[edited]