1

I want to make imshow() function update (256*873)array quickly. set_array()'s speed is about 15 times a second. I hope it can be about 30 times a second. there is a demo which using imshow() and set_array().Anybody help?Thank you so much!

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()
song
  • 45
  • 1
  • 4

0 Answers0