repaint of plot in descendant plotwidget

37 views
Skip to first unread message

Robert Clement

unread,
Oct 16, 2016, 3:27:15 PM10/16/16
to pyqtgraph
Hi

I am using the development version 0.9.11 with  pyQT5 on a windows machine.

I've created a descendant of PlotWidget that catches a pypubsub message that is used to update the plot in the plotwidget.

The code for doing this is posted below.  I seems to work OK, except for the fact that  the plot stops refreshing itself after the initial number of samples is reached.

However, if I manually adjust the window size by using a mouse to drag the edge of the window then the refresh does occur as I am doing the dragging.  If I stop adjusting the window size then the plot does not update.

Any suggestions as to how I can make the plot continuously update without manual intervention.

Thanks

from __future__ import unicode_literals
import numpy as np
from pubsub import pub
import pyqtgraph_dev as pg


class ScatterPlotCanvas(pg.PlotWidget):

   
def __init__(self):
        pg
.PlotWidget.__init__(self)
       
self.xdata = [0]  
       
self.ydata = [0]  

       
self.curve = self.plot(pen='r')
       
self.enableAutoRange()    
       
self.showButtons()
       
self.samples = 100
       
        pub
.subscribe(self.receiveData,'sensor.data')

       
       
   
def updateXY(self,  xval, yval, samples):

       
if len(self.xdata) == 1:
           
self.xdata = [xval, xval]  
           
self.ydata = [yval, yval]  
       
else:
           
if len(self.xdata) > samples:
               frm
= len(self.xdata)-samples
               
self.xdata = self.xdata[frm:]
               
self.ydata = self.ydata[frm:]

           
self.xdata = np.append(self.xdata,xval)    
           
self.ydata = np.append(self.ydata,yval)  
   

       
self.curve.setData(x=self.xdata, y=self.ydata)
       
       
self.update()
       
#self.repaint()
       
#pg.QtGui.QApplication.processEvents()

   
def receiveData(self, arg1=None, arg2=None):
       
if arg1 is not None:
           xval
= arg2[0,:]
           yval
= arg2[1,:]
           
for x,y in zip(xval, yval):
             
self.updateXY(x, y, self.samples)



          

Reply all
Reply to author
Forward
0 new messages