我正在尝试制作一个基于这个例子的动画。我的主要问题是我不知道如何将动画与errorbar连接起来。也许有人已经解决了类似的问题..
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as 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 the data
return line,
#Init only required for blitting to give a 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()发布于 2013-04-09 06:12:06
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as 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 the 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 the data
bottoms.set_ydata(y - yerr)
tops.set_ydata(y + yerr)
return line, bottoms, tops
def init():
# make an 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()这将把你带到大部分的地方。查看axes.errorbar如何工作的代码,以了解它返回的内容。
你误解了init的作用。
如果你需要垂直线,看看如何在axes.errorbar中生成,然后在每一帧中删除并重新创建它们。基于collection的对象在更新时表现不佳。
https://stackoverflow.com/questions/15887820
复制相似问题