动画与matplotlib pcolormesh常规,我怎么初始化数据? [英] Animation with pcolormesh routine in matplotlib, how do I initialize the data?
问题描述
我试图在动画一个matplotlib pcolormesh。我看过很多的使用包的动画,大多采用一维的情节套路的例子,其中有些与imshow()。
首先,我婉使用FuncAnimation程序。我的问题是,第一,我不知道我是否可以初始化的情节。
I am trying to animate a pcolormesh in matplotlib. I have seen many of the examples using the package animation, most of them using a 1D plot routine, and some of them with imshow(). First, I wan to use the FuncAnimation routine. My problem is, first, that I do not know if I can initialize the plot
fig,ax = plt.subplots()
quad = ax.pcolormesh(X,Y,Z)
我已经尝试了几行简单:
I have tried a few simple lines:
fig,ax = plt.subplots()
quad = ax.pcolormesh([])
def init():
quad.set_array([])
return quad,
def animate(ktime):
quad.set_array(X,Y,np.sin(Z)+ktime)
return quad,
anim = animation.FuncAnimation(fig,animate,init_func=init,frames=Ntime,interval=200,blit=True)
plt.show()
plt.show()
顺便说一句,我如何设置成标签和动画的情节?我可以动画标题,如果它显示了许多改变的时间?
谢谢
By the way, How do I set labels into and animated plot? Can I animate the title, if it is showing a number that changes in time? Thanks
推荐答案
我不知道为什么你的四= ax.pcolormesh(X,Y,Z)函数给了一个错误。你能后的错误?
I am not sure why your quad = ax.pcolormesh(X,Y,Z) function is giving an error. Can you post the error?
下面是我会做什么用pcolormesh创建一个简单的动画:
Below is what I would do to create a simple animation using pcolormesh:
import matplotlib.pyplot as plt
import numpy as np
y, x = np.meshgrid(np.linspace(-3, 3,100), np.linspace(-3, 3,100))
z = np.sin(x**2+y**2)
z = z[:-1, :-1]
ax = plt.subplot(111)
quad = plt.pcolormesh(x, y, z)
plt.colorbar()
plt.ion()
plt.show()
for phase in np.linspace(0,10*np.pi,200):
z = np.sin(np.sqrt(x**2+y**2) + phase)
z = z[:-1, :-1]
quad.set_array(z.ravel())
plt.title('Phase: %.2f'%phase)
plt.draw()
plt.ioff()
plt.show()
一帧的:
One of the frames:
这是否帮助?如果没有,也许你可以厘清的问题。
Does this help? If not, maybe you can clarify the question.
这篇关于动画与matplotlib pcolormesh常规,我怎么初始化数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!