[Matplotlib-users] How to improve the speed of display implemented using matplotlib

Eric Firing efiring at hawaii.edu
Tue Jun 5 02:04:47 EDT 2018

I think that at least part of the problem is that in RepeatPlot you are 
piling one image plot on top of another.  Instead, keep a reference to 
the image object (let's call it "im") returned from your first call to 
imshow, in LivePlot, and then, in RepeatPlot, instead of calling imshow 
again, just call "self.im.set_data(image)".


On 2018/06/04 7:30 PM, aishwarya selvaraj wrote:
> Hi all,
> I have 2 files created, one a .pyx file with a class named 
> AndorCamersSDK which has a function named LiveAcquisition(). The second 
> file, a .py file with a Class AndorCameraGUI which makes use of Tkinter 
> to create a GUI. This class has function LivePlot(), and 
> RepeatPlot().Inside LiveAcquisition() I am acquiring N number of frames 
> and after acquiring each frame I need to display it using LivePlot() and 
> RepeatPlot(). Without the display, just acquiring and storing for 300 
> frames takes 6.2 for execution, which is fine by me. But When I start 
> displaying even for 100 frames it takes 54sec. I need to acquire and 
> display within 6 sec for 300 frames. How do I solve this?
> File 1: .pyx code ; Present inside class AndorCameraSDK
> |defLiveAcquisition(self):fori 
> inrange(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|
> File 2 : .py code; Below functions are present inside a class named 
> AndorCameraGUI
> |defLivePlot(self,image):self.count =0self.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 figureself.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 defRepeatPlot(self,image):image 
> =image.transpose()self.a.imshow(image,'gray')self.canvas.draw()|
> -- 
> Regards,
> Aishwarya Selvaraj
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users

More information about the Matplotlib-users mailing list