Skip to content

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

Closed

Description

@emazep

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

Activity

  1. changed the title [-][Bug]: [/-] [+][Bug]: First invocation of plt.plot() resets mpl.rcParams['figure.dpi'][/+] on May 7, 2022
  2. jklymak commented on May 7, 2022

    @jklymak
    Member

    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.

  3. anntzer commented on May 8, 2022

    @anntzer
    Contributor
  4. emazep commented on May 8, 2022

    @emazep
    Author

    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).

  5. yut23 commented on May 9, 2022

    @yut23

    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.

  6. tacaswell commented on May 10, 2022

    @tacaswell
    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.

  7. neon-ninja commented on May 18, 2022

    @neon-ninja

    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

  8. tacaswell commented on May 18, 2022

    @tacaswell
    Member

    Has anyone reported this to matplotlib-inline?

  9. neon-ninja commented on May 18, 2022

    @neon-ninja

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

  10. juanitorduz commented on May 18, 2022

    @juanitorduz

    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

  11. added a commit that references this issue on May 20, 2022
  12. mikofski commented on May 24, 2022

    @mikofski

    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?

  13. timhoffm commented on Oct 16, 2022

    @timhoffm
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions