Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix bug where matplotlib.style('default') resets the backend #17252

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

Merged
merged 1 commit into from
Apr 28, 2020

Conversation

lukelbd
Copy link
Contributor

@lukelbd lukelbd commented Apr 27, 2020

PR Summary

This is a two-line PR that fixes an issue where matplotlib.style('default') resets the backend.

While matplotlib.style._remove_blacklisted_style_params tries to prevent resetting the backend, it fails due to the implementation of RcParams.__getitem__. Basically these lines:

def _remove_blacklisted_style_params(d, warn=True):
o = {}
for key, val in d.items():

end up triggering these lines when the 'backend' key comes up:

elif key == "backend":
val = dict.__getitem__(self, key)
if val is rcsetup._auto_backend_sentinel:
from matplotlib import pyplot as plt
plt.switch_backend(rcsetup._auto_backend_sentinel)

To repair this, I change the _remove_blacklisted_style_params iteration from for key, val in d.items() to for key in d.keys():, which prevents triggering the __getitem__ override.

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@QuLogic
Copy link
Member

QuLogic commented Apr 27, 2020

Can you do plain for k in d:, or does that trigger something too?

@lukelbd lukelbd force-pushed the bugfix_default-style-backend branch from 49638cd to 23470a8 Compare April 27, 2020 23:45
@lukelbd
Copy link
Contributor Author

lukelbd commented Apr 27, 2020

Nope that works fine. Just changed it.

@tacaswell tacaswell added this to the v3.2.2 milestone Apr 28, 2020
@QuLogic QuLogic merged commit 68652b1 into matplotlib:master Apr 28, 2020
@QuLogic
Copy link
Member

QuLogic commented Apr 28, 2020

Thanks @lukelbd!

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 28, 2020
QuLogic added a commit that referenced this pull request Apr 28, 2020
…252-on-v3.2.x

Backport PR #17252 on branch v3.2.x (Fix bug where matplotlib.style('default') resets the backend)
@lukelbd lukelbd deleted the bugfix_default-style-backend branch April 28, 2020 08:35
@tacaswell
Copy link
Member

Congratulations on your first Matplotlib PR 🎉 ! Hopefully we will hear from you again.

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

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.