title: How to clear a plot in a `while` loop when using PyQtGraph?
body: <p>I am using PyQtGraph for a speedy visualization of my data acquisition. For this I am redrawing the data constantly using a <code>while</code> loop. A simplified version of this code is given by:</p>
  
  <pre><code>import time
  import numpy
  import pyqtgraph as pg
  from pyqtgraph.Qt import QtGui, QtCore
  
  x = numpy.linspace(-2 * numpy.pi, 2 * numpy.pi, 1000)
  y = numpy.cos(x)
  
  # Plot
  win = pg.GraphicsWindow()
  win.resize(800, 800)
  
  p = win.addPlot()
  p.plot(x, y, pen = "y")
  
  i = 0
  while i &lt; 5000:
    start_time = time.time()
  
    noise = numpy.random.normal(0, 1, len(y))
    y_new = y + noise
  
    p.plot(x, y_new, pen = "y", clear = True)
    p.enableAutoRange("xy", False)
  
    pg.QtGui.QApplication.processEvents()
  
    i += 1
  
    end_time = time.time()
    print("It has been {0} seconds since the loop started".format(end_time - start_time))
  
  win.close()
  </code></pre>
  
  <p>When I time each iteration I find that I am not properly clearing the graph. The iteration time just keeps on increasing, and I am slowing down my data acquisition. For the example above, the iteration time in the beginning is about <code>0.009 s</code> whereas at the end it is about <code>0.04 s</code>. I therefore have a memory-leak.</p>
  
  <p>I know that in <code>matplotlib</code> I should be calling be <code>clf()</code> to properly clear the plot. Unfortunately I am not that familiar with PyQtGraph and thought the <code>clear = True</code> would take care of this issue. I am confident it should be possible as <code>PyQtGraph</code> was designed for this type of usage. </p>
  
  <p>How should I clear the graph each iteration to make sure I am not slowing down my data acquisition?</p>