question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refresh Output widget with matplotlib figure

See original GitHub issue

Hi!

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:open
  • Created 6 years ago
  • Reactions:2
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
pbugnioncommented, Jan 29, 2018

(I edited your comment to put the code in a code block to make it easier to read)

0reactions
jasongroutcommented, Mar 5, 2019

Typically, you should either do:

with out:
    clear_output(wait=True)
    display(ax.figure)

OR do:

out.clear_output(wait=True)
out.display(ax.figure)

Are you saying that you had better results with your variant above?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found