[英]How do I tell python what my data structure (that is in binary) looks like so I can plot it?
[英]How can I animate my graph with matplotlib so that it looks like the data points are moving?
我有两个2D数组,我想在散点图中显示数据,以便看起来像点在移动。 所以我想绘制第一组x和y数据,然后消失以替换为下一组x和y数据,等等。
我目前使用的代码只是绘制所有数据点并将它们连接起来,从而有效地找出数据点的路径。
pyplot.figure()
for i in range(0,N):
pyplot.plot(x[i,:],y[i,:],'r-')
pyplot.xlabel('x /m')
pyplot.ylabel('y /m')
pyplot.show()
任何帮助深表感谢。
matplotlib
文档包含一些可能有用的动画示例 。 他们都使用matplotlib.animation
API,因此建议您通读一下以获取一些想法。 从示例中,这是一个使用FuncAnimation
的简单动画正弦曲线:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
x = np.arange(0, 2*np.pi, 0.01) # x-array
line, = ax.plot(x, np.sin(x))
def animate(i):
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():
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.