Giter VIP home page Giter VIP logo

Comments (14)

trchudley avatar trchudley commented on August 22, 2024 7

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.

jasongrout avatar jasongrout commented on August 22, 2024 3

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.

SylvainCorlay avatar SylvainCorlay commented on August 22, 2024 1

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.

EricGallimore avatar EricGallimore commented on August 22, 2024 1

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.

martinRenou avatar martinRenou commented on August 22, 2024 1

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.

martinRenou avatar martinRenou commented on August 22, 2024 1

There is this open PR here: #176

We discussed potential solutions there.

from ipympl.

FeldrinH avatar FeldrinH commented on August 22, 2024 1

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.

jenshnielsen avatar jenshnielsen commented on August 22, 2024

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

SylvainCorlay avatar SylvainCorlay commented on August 22, 2024

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

jenshnielsen avatar jenshnielsen commented on August 22, 2024

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.

gsaurabhr avatar gsaurabhr commented on August 22, 2024

Any update on this? This issue still persists...

from ipympl.

SylvainCorlay avatar SylvainCorlay commented on August 22, 2024

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

ipcoder avatar ipcoder commented on August 22, 2024

Since this problem seems to be around, can we provide at least a practically useful solution?
Here are some suggestions:

  1. Allow an option to switch into a mode in which when closing a widget the figure is closed as well.
  2. Add "close" button which will close the widget AND the figure
  3. Add a "freeze" button which will close the widget, the figure but leave the image like in "inline" mode
  4. 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.

BrenBarn avatar BrenBarn commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.