我想快速制作imshow()函数更新(256 * 873)数组。 set_array()的速度大约是每秒15次。我希望它可以达到每秒30次左右。有一个使用imshow()和set_array()的演示。有人帮忙吗?非常感谢你!
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
import numpy as np
TIMER_ID = wx.NewId()
class CanvasFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'SinWave', size=(600,600))
self.figure = Figure()
self.canvas = FigureCanvas(self, -1, self.figure)
self.axes = self.figure.add_subplot(111)
mapdata = np.random.rand(256, 873)
self.img_artist = self.axes.imshow(mapdata, origin='lower', interpolation='nearest', aspect='auto',extent=[0,873,0,256])
self.img_artist.set_clim(vmin=0, vmax=1)
self.timer = wx.Timer(self) # 创建定时器
self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)
self.timer.Start(100) # 设定时间间隔
self.cnt=0
def OnTimer(self, evt):
mapdata = np.random.rand(256, 873)
self.img_artist.set_data(mapdata)
self.canvas.draw()
self.cnt +=1
print self.cnt
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = CanvasFrame()
frame.Show()
app.MainLoop()