【发布时间】:2016-09-15 23:21:54
【问题描述】:
Python 3.5,Windows 10 专业版。
我正在尝试连续绘制一个 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()
如果您想查看 while 循环代码,以便您确切知道我要重现的内容,请参见下文。
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)
【问题讨论】:
标签: python-3.x animation matplotlib