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

[Bug]: First invocation of plt.plot() resets mpl.rcParams['figure.dpi'] #23007

Closed
emazep opened this issue May 7, 2022 · 11 comments
Closed

[Bug]: First invocation of plt.plot() resets mpl.rcParams['figure.dpi'] #23007

emazep opened this issue May 7, 2022 · 11 comments

Comments

@emazep
Copy link

emazep commented May 7, 2022

Bug summary

First invocation of plt.plot() resets mpl.rcParams['figure.dpi'].

Code for reproduction

# Only tested in Jupyter

import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.rcParams['figure.dpi'] = 300

print(mpl.rcParams['figure.dpi'])
plt.plot()
print(mpl.rcParams['figure.dpi'])

Actual outcome

300.0
72.0

Expected outcome

300.0
300.0

Additional information

This happens only at the very first invocation of plt.plot(), while on subsequent plt.plot() calls mpl.rcParams['figure.dpi'] will no longer be overwritten.

Other rcParams values seem not to be affected (but I've not tested them all).

I have never observed this behavior in any of the previous matplotlib versions, so the bug must have been introduced in the latest version (3.5.2).

Operating system

Windows 10

Matplotlib Version

3.5.2

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.9.12

Jupyter version

3.4.0

Installation

conda

@emazep emazep changed the title [Bug]: [Bug]: First invocation of plt.plot() resets mpl.rcParams['figure.dpi'] May 7, 2022
@jklymak
Copy link
Member

jklymak commented May 7, 2022

We really need to solidify if rcParams track current state or not. I pretty strongly feel they should not track current state - the figure or its canvas tracks that. I think rcParams should be read-only from the library's point of view.

@anntzer
Copy link
Contributor

anntzer commented May 8, 2022

@emazep
Copy link
Author

emazep commented May 8, 2022

I can confirm that it does not happen in a stand-alone script (and that it has only been tested in Jupyter lab 3.4.0).

@yut23
Copy link

yut23 commented May 9, 2022

This has newly appeared in 3.5.2 due to #22005 making IPython's integration code run at the first use instead of at import. Before, it would just override the relevant values set in the matplotlibrc file and not interfere with any runtime changes to rcParams.

@tacaswell
Copy link
Member

This has newly appeared in 3.5.2 due to #22005 making IPython's integration code run at the first use instead of at import

Sigh, making this lazier always produces interesting unintended consequences.

We really need to solidify if rcParams track current state or not. I pretty strongly feel they should not track current state ...

I think the only rcParam that we mutate for the user is the save-folder location (which the user has to opt-into the behavior). We had a long discussion about that and concluded it was better to just leave that as it is rather than go through the effort of deprecating that behavior and moving the global state someplace else for the sake of aesthetics.

@neon-ninja
Copy link

I'm having this problem too, with plt.rcParams['figure.figsize']. Rolling back to matplotlib==3.5.1 with pip install matplotlib==3.5.1 fixes it

@tacaswell
Copy link
Member

Has anyone reported this to matplotlib-inline?

@neon-ninja
Copy link

neon-ninja commented May 18, 2022

This PR in matplotlib-inline would fix the issue - ipython/matplotlib-inline#14

@juanitorduz
Copy link

I am having the same issue and I thought it was because of a new vscode release (microsoft/vscode-jupyter#9991 (comment)) but it also happens in google colab

fperez added a commit to ipython/matplotlib-inline that referenced this issue May 20, 2022
@mikofski
Copy link

I was having a similar issue with rcParams['figure.figsize'], see https://discourse.matplotlib.org/t/bug-rcparams-doesnt-work-first-time-v3-5-2/22853, downgrading to mpl-3.5.1 solved the issue. IDK if it's the same?

@timhoffm
Copy link
Member

This PR in matplotlib-inline would fix the issue - ipython/matplotlib-inline#14

was released in matplotlib-inline 0.1.4 (Aug. 14, 2022). So I think we can close this.

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

10 participants