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

Surprising behaviour from plt.style.use('theme'), themes being not exclusive #26779

Open
kraktus opened this issue Sep 14, 2023 · 3 comments
Open

Comments

@kraktus
Copy link

kraktus commented Sep 14, 2023

Thank you for your work on this cornerstone lib.

Bug summary

Not a bug, since documented, but still a surprising behavior from plt.style.use('theme') not resetting values to the default before applying the new ones. Apologies if an issue already exist, didn't find one.

This updates the rcParams with the settings from the style. rcParams not defined in the style are kept.

This is especially an issue when using jupyter notebook for example, where one's would cycle through themes before sticking to one they think look good, while it's a mix of multiple themes and dependent of the order in which they've tried it!

Code for reproduction

plt.style.use("seaborn-v0_8-dark")
plt.style.use("dark_background")
# ...

Actual outcome

Mix of both styles.

Expected outcome

equivalent to

plt.style.use("dark_background")
# ...

Additional information

From what I've seen plotting appearance falls under breaking change, but I don't know how strict this is enforced. I'd expect people willingly setting multiple themes at the same time to get a custom style chimera to be quite small.

@kraktus kraktus changed the title [Bug]: plt.style.use('theme') are not exclusive Surprising behaviour from plt.style.use('theme'), themes being not exclusive Sep 14, 2023
@jklymak
Copy link
Member

jklymak commented Sep 15, 2023

@kraktus I think that is one of the reasons we have a theme context manager:

with plt.style.use('seaborn-v0_8-dark'): 
   plot() # seaborn theme

plot() # old theme 

People want to compose themes quite often (apply some of one theme, some of another) so, back compatibility aside, I expect it is unlikely that we will revert to default every time style.use is called.

@timhoffm
Copy link
Member

timhoffm commented Sep 15, 2023

We are good

The behavior is documented correctly: https://matplotlib.org/stable/api/style_api.html#matplotlib.style.use

Can we be better?

The default will not change, but possible extensions are:

  • adding a parameter to start from default or
  • allow styles to specify whether they are incremental to the current state or whether they are based on default (or another style). This is likely better than the parameter because whether a style is incremental or not is basically a static design decision of that style. It should be rare that one wants the same style config incremental in one case and absolute in another.

@tacaswell
Copy link
Member

When we brought is styles the ability to compose them like this was one of the explicit design goals. If a style wants to be against the default, then it should copy more of the default values into itself.

This is something that the chainmap work @chahak13 has going may help with. Currently we can only say "go back to default" and no way to say "please undue the last style application" (short of the context manager).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants