python - Animation by using matplotlib + errorbar -
i'm trying make animation based on example. main problem don't know how connect animation errorbar. maybe has solved similar ..
import numpy np import matplotlib.pyplot plt import matplotlib.animation animation line, = ax.plot(x, np.sin(x)) def animate(i): ax.errorbar(x, np.array(x), yerr=1, color='green') line.set_ydata(np.sin(x+i/10.0)) # update data return line, #init required blitting give clean slate. def init(): ax.errorbar(x, np.array(x), yerr=1, color='green') line.set_ydata(np.ma.array(x, mask=true)) return line, ani = animation.funcanimation(fig, animate, np.arange(1, 200), init_func=init, interval=25, blit=true) plt.show()
import numpy np import matplotlib.pyplot plt import matplotlib.animation animation fig = gcf() ax = gca() x = np.linspace(0, 2*np.pi, 256) line, ( bottoms, tops), verts = ax.errorbar(x, np.sin(x), yerr=1) verts[0].remove() # remove vertical lines yerr = 1 def animate(i=0): # ax.errorbar(x, np.array(x), yerr=1, color='green') y = np.sin(x+i/10.0) line.set_ydata(y) # update data bottoms.set_ydata(y - yerr) tops.set_ydata(y + yerr) return line, bottoms, tops def init(): # make empty frame line.set_ydata(np.nan * np.ones(len(line.get_xdata()))) bottoms.set_ydata(np.nan * np.ones(len(line.get_xdata()))) tops.set_ydata(np.nan * np.ones(len(line.get_xdata()))) return line, bottoms, tops ani = animation.funcanimation(fig, animate, np.arange(1, 200), init_func=init, interval=25, blit=true) plt.show()
this of way there. code of how axes.errorbar
works understand returns.
you misunderstood init
does.
if need have vertical lines, @ how generate in axes.errorbar
, remove , re-create them every frame. collection
based objects not play nice updating.
Comments
Post a Comment