Comments (14)
I'd like to return to this and say this feature (or a toggle-able option to enable it) is something I'd very much appreciate on a user side. I often iterate plots visualising large arrays or images, and since moving from %matplotlib notebook
to %matplotlib widget
this has frequently becomes unwieldy when old figures are stored in-memory. Appending plt.close()
to the top of a cell is an interim solution, but not always desired when you're also jumping between different figures in a notebook.
I can follow this thread from here to #176 to #343, but slowly these solutions stop addressing the problem @jenshnielsen raised originally (although a stop button as per #176 would also be appreciated to help me manage figure memory!). I've seen discussion touch upon the topic in #60 (here) #171 (here) but nothing seems to have come of it.
Has there been a conclusive decision to address or not address this issue that I have missed in my search? If not, please take this as another request from an end-user to provide an option to address this issue!
from ipympl.
As @jkrumbiegel points out at jupyterlab/jupyterlab#5373, it can also be confusing to get this error by just evaluating the cell creating the figure over and over again.
from ipympl.
We could close the figure when the jupyter comm is closed, and reversely. That would be a sensible thing to do in my opinion.
from ipympl.
Would it be possible to eliminate the cross-language counting problem by adding a magic directive that allows a user to specify that there will only be one view of the widget?
That way, it doesn't break any of the more complicated use cases. For the the 99% of cases where only one view of a figure is used, it solves this issue.
from ipympl.
This is an open-source project and everyone is welcome to contribute. Maybe you would like to open a Pull Request @ReblochonMasque? I would be very happy to merge it.
from ipympl.
There is this open PR here: #176
We discussed potential solutions there.
from ipympl.
Old figures remaining active when re-executing the cell is particularly problematic when trying to write helper functions.
Calling plt.close()
or reusing the same figure might be workable in top level code. However, when trying to write a general purpose helper function that needs to create figures, it quickly becomes impossible to avoid situations where previous figures disappear, get overwritten or stop responding.
If there was some way to automatically close figures that are no longer visible then that would be a huge help.
from ipympl.
@SylvainCorlay Do you have any idea of how to hook this up to the widgets and send a close message to python when the widget is destroyed/closed from the notebook
from ipympl.
@jenshnielsen we can't to the latter because the close button only destroys a view. There may be other views of the same widget. And even when there is no view, the widget model could be wired to other widget models in the front end. Essentially it is a cross-language reference counting problem.
from ipympl.
That makes sense.
There is is certain mismatch between the Matplotlib APIs which and designed around GUI frameworks where there is a 1 to 1 relation ship between a figure window and it's python representation and the widgets. We will have to think more about how to handle this
from ipympl.
Any update on this? This issue still persists...
from ipympl.
@gsaurabhr as per comment above, this is somewhat by design:
@jenshnielsen we can't to the latter because the close button only destroys a view. There may be other views of the same widget. And even when there is no view, the widget model could be wired to other widget models in the front end. Essentially it is a cross-language reference counting problem.
This gets more complicated if you account from multiple notebooks / front-end connected to the kernels.
from ipympl.
Since this problem seems to be around, can we provide at least a practically useful solution?
Here are some suggestions:
- Allow an option to switch into a mode in which when closing a widget the figure is closed as well.
- Add "close" button which will close the widget AND the figure
- Add a "freeze" button which will close the widget, the figure but leave the image like in "inline" mode
- Add something like
freeze_figure()
function to do that programmatically.
I would say 1
should be implemented at first priority for multiple reasons:
- its safe, that is by default changes nothing from what it is now
- addresses directly the root cause of the problem:
There is is certain mismatch between the Matplotlib APIs which and designed around GUI frameworks where there is a 1 to 1 relation ship between a figure window and it's python representation and the widgets.
2
& 3
would be very handy for daily work with notebooks.
from ipympl.
Would it be possible to eliminate the cross-language counting problem by adding a magic directive that allows a user to specify that there will only be one view of the widget?
I agree this would be a good thing to look into. And ideally also have a super-magic directive that says "all of my ipympl widgets will always ever have only one view each".
It's great that the notebook and matplotlib support all these complicated use cases but 90% of the time you're just plotting each plot in one cell and you want it to work. We shouldn't let that overwhelmingly prevalent use case become blocked by the possibility of obscure cases where someone's trying to re-use a widget in multiple places.
from ipympl.
Related Issues (20)
- Unable to access ipympl from JupyterLab due to Error displaying widget: model not found
- Question: should I use `%matplotlib widget` or `%matplotlib ipympl` HOT 4
- DepreciationWarning in toolbar causes AttributeError
- ipympl crashes when panning/zooming
- JupyterLab 4.x support HOT 4
- [FR] Cursor Control HOT 1
- Latest version of everything still causes the dreaded Error displaying widget: model not found HOT 11
- An error in use of inset_axes of mpl_toolkits in Jupyter Notebook HOT 2
- [email protected]
- Comptability with mpl cursors
- Failed to load model class 'MPLCanvasModel' from module 'jupyter-matplotlib' Error: No version of module jupyter-matplotlib is registered. HOT 6
- Please remove jupyterlab==3.* requirement so as to allow 4.x to work. HOT 3
- Ability to configure defaults for `Canvas`
- Interactive graph - Saving
- Error: No version of module jupyter-matplotlib is registered HOT 5
- [test-bot] Scheduled Tests are failing
- Matplotlib Fails to Update Axis Limits with ipywidgets in Jupyter Lab HOT 1
- Question: how to use ipympl to simply include axes in ipywidets layout? HOT 1
- Large top/bottom padding for imshow images HOT 5
- Blank figures in Jupyter notebook HOT 13
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 ipympl.