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)