title: Remove / Delete Legend in PyQtGraph
body: <p>Two lines are created on the live chart and a legend is added. At the next update, the lines on the chart are deleted using self.pw.clear().</p>
  
  <p>But the legend is not deleted, and with each update, a new instance of the legend is added, there are a lot of them and the FPS of the schedule update quickly drops.</p>
  
  <p>Here <a href="http://www.pyqtgraph.org/documentation/graphicsItems/plotitem.html" rel="nofollow noreferrer">http://www.pyqtgraph.org/documentation/graphicsItems/plotitem.html</a> says Clear(): “Remove all items from the ViewBox.”</p>
  
  <p>Attempting to Clear / removeItem - have not yet helped (either the syntax is incorrect, or the procedure call is incorrect).</p>
  
  <p><strong>How to delete a legend when updating a chart or stop multiple legends creation?</strong></p>
  
  <pre><code>import random
  from PyQt5 import QtGui
  import pyqtgraph as pg
  import sys
  
  class Mainwindow(QtGui.QMainWindow):
      def __init__(self, parent):
          super(Mainwindow, self).__init__()
          self.centralWidget = QtGui.QWidget()
          self.setCentralWidget(self.centralWidget)
          self.resize(1000, 500)
  
          self.vbox = QtGui.QVBoxLayout()
          self.pw = pg.PlotWidget()
          self.vbox.addWidget(self.pw)
          self.centralWidget.setLayout(self.vbox)
  
          # Update chart
          self.timer = pg.QtCore.QTimer()
          self.timer.setSingleShot(False)
          self.timer.timeout.connect(self.update)
          self.timer.start(10)
  
      def update(self):
          x = []
          y = []
          z = []
          for i in range(10000):
              x.append(i)
              y.append(random.uniform(0, 1))
              z.append(1 + random.uniform(0, 1))
  
          self.pw.clear()
          line_red = pg.PlotCurveItem(x, y, clear=True, pen='r', name='Red')
          line_yellow = pg.PlotCurveItem(x, z, clear=True, pen='y', name='Yellow')
          self.pw.addItem(line_red)
          self.pw.addItem(line_yellow)
          self.pw.addLegend()
  
  app = QtGui.QApplication(sys.argv)
  ex = Mainwindow(app)
  ex.show()
  sys.exit(app.exec_())
  </code></pre>