如何使用matplotlib提高显示速度

时间:2018-06-04 13:50:09

标签: python matplotlib tkinter cython pyqtgraph

我创建了2个文件,一个是带有名为AndorCamersSDK的类的.pyx文件,其中有一个名为LiveAcquisition()的函数。第二个文件,带有AndorCameraGUI类的.py文件,它使用Tkinter创建GUI。这个类有函数LivePlot()和RepeatPlot()。在LiveAcquisition()里面我获取N个帧,在获取每个帧后我需要使用LivePlot()和RepeatPlot()显示它。没有显示器,只需获取和存储300帧就可以执行6.2,这对我来说很好。但是当我开始显示甚至100帧时,它需要54秒。我需要在6秒内获取并显示300帧。我该如何解决这个问题?

文件1:.pyx代码;介绍AndorCameraSDK课程内部

def  LiveAcquisition(self):
    for i in range(no_of_frames): 
        data[i,:,:] = PyArray_NewFromDescr(<PyTypeObject *> np.ndarray, np.dtype('<H'), 2,dims, strides,pBuf, np.NPY_C_CONTIGUOUS, None)
        if (i==0):
            self.master.LivePlot(data[i,:,:])
        elif (i==2) or (i==15) or (i ==65) or (i ==96):
            self.master.RepeatPlot(data[i,:,:])
        else:
            pass

文件2:.py代码;下面的函数存在于名为AndorCameraGUI的类中

def LivePlot(self,image):
    self.count = 0
    self.fig = Figure(figsize = (4, 5))
    self.fig.patch.set_facecolor('xkcd:light grey') # When this is removed a white color is seen in the background of the figure
    self.a = self.fig.add_subplot(111)
    self.a.set_xlim([0, self.image_width/int(self.HBin)])
    self.a.set_ylim([0, self.image_height/int(self.VBin)])
    image = image.transpose()
    self.a.imshow(image,'gray')
    self.canvas = FigureCanvasTkAgg(self.fig,self.master)
    self.canvas.draw()
    self.canvas.get_tk_widget().pack(side =LEFT)
    self.toolbar = NavigationToolbar2TkAgg(self.canvas,self.master)
    self.toolbar.update()
    self.canvas._tkcanvas.pack(side = LEFT)# change this to TOP so thee the navigation toolbar on the left down

def RepeatPlot(self,image):
    image = image.transpose()
    self.a.imshow(image,'gray')
    self.canvas.draw()

0 个答案:

没有答案