You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
backend partially ignores "figure.figsize" in plt.rc_context in jupyter #23513
in mpl 3.5.2 we deferred importing the backend until we absolutely had to (this fixed some bugs with the Qt backend and has been a long-term goal) rather than at pyplot first import time
matplotlib-inline sets rcparams at it's import time
Due to the delayed import matplotlib-inline is now imported inside of the context manager which overrides your values (and which the context sets back to what it was before on exit which hides the state change!). The call to plt.show() fixes the problem because it forces the import to be earlier. Simlarly, running the cell a second time works because the module is already imported and hence does not change the rcparams.
Adding plt.get_backend() will also force the import and is the work-around I would go with for now (it should work on all versions of mpl / matplotlib-inline and is mostly harmless).
I am going to close this issue because we understand it and a fix has been merged downstream. Sorry we broke this on you.
Thank you very much for the really quick and insightful answer. However, when I put plt.get_backend() in-between the import and the context section, it has no effect like plt.show(). I noticed plt.clf() works as well. However, in both cases I don't know if I generate some potential pitfalls.
One day I will learn to always test my suggestions before suggesting....
I (incorrectly) thought that you would be going through the backend fallback logic so checking the would do import the backend module, but there is actually a string already set so get_backend is fast and has no side effects 🤦🏻 .
Instead doing:
import matplotlib_inline # side effect of changing the rcParams
will definitely import the module and trigger the rcparam changing logic.
However, somewhere in the machinery the module already got imported, which then hinders the re-execution of _enable_matplotlib_integration()
You can see it via, e.g.,
import sys
sys.modules["matplotlib_inline"]
However, explicitly importing it into a new namespace works:
Activity
tacaswell commentedon Jul 29, 2022
I suspect that this is fixed by ipython/matplotlib-inline#14
The interaction here is:
Due to the delayed import matplotlib-inline is now imported inside of the context manager which overrides your values (and which the context sets back to what it was before on exit which hides the state change!). The call to
plt.show()fixes the problem because it forces the import to be earlier. Simlarly, running the cell a second time works because the module is already imported and hence does not change the rcparams.Adding
plt.get_backend()will also force the import and is the work-around I would go with for now (it should work on all versions of mpl / matplotlib-inline and is mostly harmless).I am going to close this issue because we understand it and a fix has been merged downstream. Sorry we broke this on you.
juhuebner commentedon Jul 29, 2022
@tacaswell
Thank you very much for the really quick and insightful answer. However, when I put
plt.get_backend()in-between the import and the context section, it has no effect likeplt.show(). I noticedplt.clf()works as well. However, in both cases I don't know if I generate some potential pitfalls.tacaswell commentedon Jul 29, 2022
One day I will learn to always test my suggestions before suggesting....
I (incorrectly) thought that you would be going through the backend fallback logic so checking the would do import the backend module, but there is actually a string already set so
get_backendis fast and has no side effects 🤦🏻 .Instead doing:
will definitely import the module and trigger the rcparam changing logic.
juhuebner commentedon Aug 3, 2022
There is still something fishy with this import.
You are probably referring to https://github.com/ipython/matplotlib-inline/blob/f764b4354b2358aa001471215494d7dfdc505593/matplotlib_inline/backend_inline.py#L227
However, somewhere in the machinery the module already got imported, which then hinders the re-execution of
_enable_matplotlib_integration()You can see it via, e.g.,
However, explicitly importing it into a new namespace works:
tacaswell commentedon Aug 3, 2022
I did not learn my lesson about testing in the post where I noted needing to learn my lesson about testing 🤦🏻