-
Notifications
You must be signed in to change notification settings - Fork 226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop button #176
Stop button #176
Conversation
Signed-off-by: martinRenou <martin.renou@gmail.com>
One idea would be to remove the interactive widget Not sure I have all the implementation details in mind, but I feel like that would be an elegant way of solving this issue. |
This is a really important feature. After "closing" , all plots should be simple PNG files in the Notebook. That enables us to export the whole notebook as html, pdf etc. Is this workflow already possible with this PR? What is still missing? (By the way, with the matplotlib 'notebook' backend this is already possible for normal 'Jupyter' notebooks. Not for 'JupyterLab', yet.) |
This PR is not really fixing this issue properly.
I think we should take a different approach than what this PR is doing. The approach would be the one I tried to explain on the comment on top of yours: When the close button is pressed, or when the Matplotlib figure is closed using the Python API, we should actually remove the Widget and replace it with a plain image in the cell output. |
Recently, I tried to obtain the PNG using the renderer of the 'widget' backend obtained with 'fig.canvas.get_renderer()' . But it only returned a buffer with all pixels of the same color, i.e. without the actual plot. Don't know what I have to call in advance. 'fig.canvas.draw()' does not help, which is little bit confusing. |
Big fan of this feature existing. I'm willing to help - but any advice on what the appropriate way to accomplish this is would be great. Is this PR: #59 the approach to take? |
Looking at it further I do think that #59 shows gives the "implementation details" My understanding is that the if not self.closed:
Super()._repr_mimebundle()
else:
"<img src='data:image/png;base64,{......}'/>" |
In https://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html#functions it says that:
but if you define multiple of them then it's not clear how to signal which one should take precedence. |
I think that is actually the problem with the PR you pointed to. If I'm correct, it's the UI that chooses which representation to display. I think the widgets representation would always take precedence over the HTML one.
Honestly, I really don't know. I would love to see a feature like this. And I think it's a big blocker for people to switch from the inline back-end to the widget one. If you want to implement this you are very welcome to do so! :) I am wondering if we could use a smart |
Some issues that look relevant: and for completeness: https://gitter.im/jupyter-widgets/Lobby?at=5f0ea2e30d37916fda770757 |
Reading jupyter-widgets/ipywidgets#2682 I feel like we have our solution! The person here seem to be able to use We would not have the issue the person mentions, simply because we would remove the widget representation so no need for re-rendering the widget, instead the UI would re-render the plot as a static image. This is what we want I guess, what do you think? :) So I guess we can reuse the close button here, but this close button would send a figure "close" request to the Matplotlib API. |
Would these lines ipympl/ipympl/backend_nbagg.py Lines 294 to 295 in 64ee6af
|
To be totally honest with you I am not really comfortable with the Python code in this repository, it was copied from the nbagg back-end if I'm correct. What if you override the |
Sadly that makes two of us It looks like the nbagg backend (only works in notebook not in jlab) has figured out how to embed the plot as an image: with relevant js code here: https://github.com/matplotlib/matplotlib/blob/81a560ccff1b1e369641a8687fe132d202037d4a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js#L162-L168 Button calls a js method (https://github.com/matplotlib/matplotlib/blob/81a560ccff1b1e369641a8687fe132d202037d4a/lib/matplotlib/backends/web_backend/js/nbagg_mpl.js#L53-L66) that just sets the parent node So that works but it seems that the discussed mime_bundle is a more principled approach |
If you do |
See the discussion in matplotlib/matplotlib#17891 for more details about how Matplotlib currently interacts with the display system. |
I spent some time messing around with rewriting the rendermime method and trying to use |
Is there a Javascript error when trying to update the display? |
This does not close #16 in my opinion. Having to remember to click each figure is still a pretty big regression from |
Maybe I am completely missing something here, but I don't see an automatic way of updating the display for replacing the widget by a static image. So either the user will have to click the button, or they will need to programmatically close the figure. |
Anyway, this PR has a draft status because it simply does not work. We'll need to find a better implementation. |
|
Not sure listening to the comm being closed would help unfortunately, but I might be wrong. I would suspect the comm is not closed if you save the Notebook, close the tab and kill the Notebook server. |
For nbagg, the image is just saved as part of the static representation, without user interaction. I have no idea if that is just fundamentally impossible for widgets or not. However, if the goal is to make a notebook available for posterity, having the static png in the notebook is a fundamental requirement. If you don't have it, then the "widget" is just a transient interactive environment. Which is fine, but I don't think ipympl should be touted as a replacement for |
What makes the difference between
We could save a One thing we were trying to look at with @ianhi was to remove the widget representation and replace it with a static
I totally agree with this. Although to be fair, ipympl has the upside of working in JupyterLab and Voila, which is not the case for nbagg. I would love to see this issue correctly fixed, any idea is very welcome. |
What we would need would be a fallback to the static HTML representation when the widget manager is not able to render the widget. That might be the perfect fix. But this is not anymore an ipympl issue then, it's an ipywidgets issue I guess, or even a Jupyter Notebook/JupyterLab issue. |
Closing as outdated. We will try another approach for saving a static representation of the plot #343 |
This should fix #150 and fix #16
It adds a "Stop interactions and embed" button which allows saving the plot as a static image in the Notebook. The output actually stays a widget, which has the last state of the plot in its model.