1
Python 3.5,windows 10 Pro。使用pcolormesh的Matplotlib.animation.FuncAnimation
我想连续绘制一个8x8像素数组(为了问题的缘故,我只是使用随机数据,但是我从串口读取的是真实的东西)。
我可以做一个while循环,但我需要切换到matplotlib.animation.FuncAnimation,我无法让它工作。我试过看帮助文件,并试图从matplotlib.org here的例子,但我一直无法遵循它。
有人可以帮我弄清楚如何使用FuncAnimation和pcolormesh连续绘制一个8x8像素数组?以下是我到目前为止有:
import scipy as sp
import matplotlib.pyplot as plt
from matplotlib import animation
plt.close('all')
y = sp.rand(64).reshape([8,8])
def do_something():
y = sp.rand(64).reshape([8,8])
fig_plot.set_data(y)
return fig_plot,
fig1 = plt.figure(1,facecolor = 'w')
plt.clf()
fig_plot = plt.pcolormesh(y)
fig_ani = animation.FuncAnimation(fig1,do_something)
plt.show()
如果你想看到的,而循环代码,只是让你知道正是我试图重现,见下文。
import scipy as sp
import matplotlib.pyplot as plt
plt.figure(1)
plt.clf()
while True:
y = sp.rand(64).reshape([8,8])
plt.pcolormesh(y)
plt.show()
plt.pause(.000001)