I used sliders in matplotlib to update a few graphs based on GUI input.
All my graphs update well.
But when I use figtext, I have the problem that the updated text will write over the existing one.
import numpy as np
import pylab as p
from matplotlib.widgets import Slider
p.subplot(111)
x = np.arange(0,500,1)
f = np.sin(x/100.0)
l11, = p.plot(f)
ax = p.axes([0.25, 0.05, 0.7, 0.03], axisbg='lightgoldenrodyellow')
slider1 = Slider(ax, 'amplitude', -1.0, 1.5, valinit=0)
def update(val):
f = slider1.val * np.sin(x/100.0)
l11.set_ydata(f)
np.set_printoptions(precision=2)
p.figtext(0.5, 0.65, str(slider1.val) )
p.draw()
slider1.on_changed(update)
p.show()
Every time you call
p.figtext(0.5, 0.65, str(slider1.val))you are creating a newTextobject which is being written on top of the previous ones. What you should do is save a reference to the firstTextobject and update its contents by calling itsset_text()method. I have updated your code with a working example.