I have an ipywidget that generates a plot each time the selection changes. Currently the plots are appended to each other; however, I would like to have only one plot (the latest).
import ipywidgets as widgets
import matplotlib.pyplot as plt
def f(change):
if change['type'] == 'change' and change['name'] == 'value':
plt.close('all') # seems to have no effect
plt.plot([0, 1],[0, 10])
plt.title(change['new'])
plt.show()
w = widgets.Select(options=[0, 1])
w.observe(f)
display(w)
I tried without success:
- using plt.close('all')
- splitting the code into two cells (even if this seems not practical for the real application)
Note: I'm not using interactive
since I do not want to run all functions when any parameter changes.