title: Pyqtgraph class: how to automatically update graph values from data buffer?
body: <p>I am using the <code>pyqtgraph</code> module to make a nice and simple real-time graph. I want to make it as a class/object that can take in a data buffer, and on update, re-read the data buffer to draw the graph. I'm having some trouble getting data buffer values from outside the class code into the object.</p>
  <p>Code below:</p>
  <pre><code>import pyqtgraph as pg
  # pip install pyqtgraph
  
  
  class App(QtGui.QMainWindow):
      def __init__(self, buffer_size, data_buffer, graph_title, parent=None):
          super(App, self).__init__(parent)
  
          #### Create Gui Elements ###########
          self.mainbox = QtGui.QWidget()
          self.setCentralWidget(self.mainbox)
          self.mainbox.setLayout(QtGui.QVBoxLayout())
  
          self.canvas = pg.GraphicsLayoutWidget()
          self.mainbox.layout().addWidget(self.canvas)
  
          self.label = QtGui.QLabel()
          self.mainbox.layout().addWidget(self.label)
  
          self.view = self.canvas.addViewBox()
          self.view.setAspectLocked(True)
          self.view.setRange(QtCore.QRectF(0,0, 100, 100))
  
          self.numDstreams = 1
          self.bufferLength = buffer_size
          self.dataBuffer = data_buffer
          self.graphTitle = graph_title
          
          self.otherplot = [[self.canvas.addPlot(row=i,col=0, title=self.graphTitle)] # , repeat line for more
                             for i in range(0,self.numDstreams)]
          self.h2 = [[self.otherplot[i][0].plot(pen='r')] for i in range(0,self.numDstreams)] # , self.otherplot[i][1].plot(pen='g'), self.otherplot[i][2].plot(pen='b')
          self.ydata = [[np.zeros((1,self.bufferLength))] for i in range(0,self.numDstreams)] # ,np.zeros((1,self.bufferLength)),np.zeros((1,self.bufferLength))
          
          for i in range(0,self.numDstreams):
              self.otherplot[i][0].setYRange(min= -100, max= 100) 
  
          self.counter = 0
          self.fps = 0.
          self.lastupdate = time.time()
  
          #### Start  #####################
          self._update()
  
      def _update(self):
      
          
          for i in range(0,self.numDstreams):
              self.ydata[i][0] = np.array(self.dataBuffer)
              
              self.h2[i][0].setData(self.ydata[i][0])
              
          
          now = time.time()
          dt = (now-self.lastupdate)
          if dt &lt;= 0:
              dt = 0.000000000001
          fps2 = 1.0 / dt
          self.lastupdate = now
          self.fps = self.fps * 0.9 + fps2 * 0.1
          tx = 'Mean Frame Rate:  {fps:.3f} FPS'.format(fps=self.fps )
          self.label.setText(tx)
          QtCore.QTimer.singleShot(1, self._update)
          self.counter += 1
          
          
  def CreateGraph(buffer_size, data_buffer, graph_title): 
          
      app1 = QtGui.QApplication(sys.argv)
      thisapp1 = App(buffer_size, data_buffer, graph_title)
      thisapp1.show()
      
      sys.exit(app1.exec_())
      return app1
      
  if __name__ == &quot;__main__&quot;:
      
      test_buffer = np.random.randn(100,)
      
      app = CreateGraph(100, test_buffer, &quot;Activity Score&quot;)
      
      while 1:
          test_buffer = np.random.randn(100,)
          app._update()
  </code></pre>
  <p>The code works in that it draws an initial graph of the random data. However, it doesn't update in the loop as I'd want. When I use this object, I want it to update its graph data buffer based on an outside variable, as I'm trying. Instead it's stacking, i.e. it only reads the data for the first time.</p>
  <h2>Edit</h2>
  <p>To be clear, I was expecting <code>test_buffer = np.random.randn(100,) app._update()</code> to update the graph continuously in the loop. I need the graph to be able to read a buffer variable in real-time and draw new data.</p>
  <p>How can I do this?</p>