Comments (2)
@petercorke, the issue you're encountering is indeed an inconsistency in behavior between the inline and notebook/ipympl/widget (let's call it widget from now on) backends.
Unfortunately, it's not completely trivial to fix. The problem is that, in order to achieve a "good user experience" in each case, over the years we had to make slightly different decisions:
- the inline backend tries to make it such that
plot(x)
"just works" in a cell by itself, giving you a plot you can see immediately, without having to muck around with creating/managing figures, etc. It also tries to make it so that, if in the next cell you typeplot(y)
, you now seey
plotted by itself, withoutx
polluting that figure (x
andy
may be totally unrelated and not make any sense if on the same figure). - the widget backend tries to give you a behavior where your figures stay interactive even if you scroll around, and you can come back and play with a previously created figure, move the axes, zoom, etc.
To achieve both of these goals, the inline backend aggressively closes figures once it's done displaying them, so you don't get "cross-cell side effects".
On the other hand, the widget one leaves them alone, for you to manage manually, so you can decide which ones you want to be interactive and which not.
Now, I don't think this state of affairs is ideal, but I've never sat down with enough time to see how to have a better experience across the two (keep in mind, the widget backend didn't exist when the inline behavior was designed, which was pre-jupyter notebook, back in 2010 for the IPython qt console).
It's possible there's a better long-term solution that @tacaswell or others have come up with. I know this is a nag for many, myself included.
But in the meantime, may I suggest you use this pattern instead. For the inline backend, when you need to manage your figures persistently (keep them alive across cells):
fig, ax = plt.subplots(...)
# do what you need with figure and axis objects
#...
fig # last line to display a figure
and you can use the same code with the widget backend. The only thing you need to do in this case is manually close figures you don't need anymore. But otherwise it's reasonably clean code that, while a bit more verbose, works well for both backends.
I hope this helps!
from matplotlib-inline.
BTW @petercorke - there's a longer discussion of this very topic in this issue on the ipympl repo, which you might find useful.
from matplotlib-inline.
Related Issues (17)
- UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte HOT 9
- docs for API calling HOT 1
- Commit schedule for matplotlib-inline HOT 20
- [Bug]: Figure manager is gone - AttributeError: 'NoneType' object has no attribute 'canvas' HOT 6
- Switch from PNG to SVG output by default? HOT 4
- `plt.ioff()` not preventing automatic figure generation in jupyter
- Figures not automatically rendered in some cases
- AttributeError: module 'matplotlib' has no attribute 'pyplot' HOT 2
- Importing `backend_inline` triggers selection of `QtAgg` backend and tie-in of GUI event loop in IPython
- Add noop `show` method to manager
- `svg` and `png` outputs are different sizes
- Optional dependency on matplotlib? HOT 10
- Retina+jpeg option? HOT 3
- Question about pypi/matplotlib-inline pointing to a fork of this project. HOT 3
- figure formatters not in this package HOT 3
- Add from `. import backend_inline` in `__init__.py` ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from matplotlib-inline.