Refresh Output widget with matplotlib figure
See original GitHub issueHi!
I deal with refresh matplotlib figure inside Output widget. The problem is that during update the Output completely disappears (or resizes to zero width / height) and appears again. I can see this because the Button follows Output in VBox and it goes to the top for some milliseconds.
The idea is like follows but my code is very complex to be posted here. But this simple example works well and my program meets the problem.
What can cause such a problem?
PS. You can see I do ax.clear() and ax.plot(…) instead of ax.set_xdata(…) That is not occasionly because my logic needs to re-plot from zero.
%matplotlib inline
# To prevent automatic figure display when execution of the cell ends
%config InlineBackend.close_figures=False
import matplotlib.pyplot as plt
import numpy as np
from IPython.html import widgets
from IPython.display import display,clear_output
plt.ioff()
ax=plt.gca()
out=widgets.Output()
button=widgets.Button(description='Next')
vbox=widgets.VBox(children=(out,button))
display(vbox)
def click(b):
ax.clear()
ax.plot(np.random.randn(100),np.random.randn(100),'+')
with out:
clear_output(wait=True)
display(ax.figure)
button.on_click(click)
click(None)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Updating matplotlib figure within Output-widget
I have a stand-alone python class which in essence holds some parameters, ... Updating matplotlib figure within Output-widget.
Read more >Matplotlib figure is not updating with ipywidgets slider
But when I drag the slider, the figure will not update. Any ideas on why this is? python · matplotlib · jupyter-notebook ·...
Read more >Ipywidgets with matplotlib - Kapernikov
We will create a matplotlib figure again, but this time inside an Output widget. Output can take all kinds of input and display...
Read more >Comprehensive Example — ipympl - Matplotlib
When you want to embed the figure into a layout of other widgets you should call ... Here is an example of using...
Read more >matplotlib.widgets — Matplotlib 3.6.2 documentation
All of these widgets require you to predefine a matplotlib.axes.Axes instance and pass that as the first parameter. Matplotlib doesn't try to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
(I edited your comment to put the code in a code block to make it easier to read)
Typically, you should either do:
OR do:
Are you saying that you had better results with your variant above?