PlotItem.addLegend will not try to add more than once

This commit is contained in:
Luke Campagnola 2017-09-15 09:05:24 -07:00
parent 9d0779cc32
commit ee0ea56695

View File

@ -602,6 +602,9 @@ class PlotItem(GraphicsWidget):
#item.connect(item, QtCore.SIGNAL('plotChanged'), self.plotChanged) #item.connect(item, QtCore.SIGNAL('plotChanged'), self.plotChanged)
#item.sigPlotChanged.connect(self.plotChanged) #item.sigPlotChanged.connect(self.plotChanged)
if self.legend is not None:
self.legend.removeItem(item)
def clear(self): def clear(self):
""" """
Remove all items from the ViewBox. Remove all items from the ViewBox.
@ -646,9 +649,13 @@ class PlotItem(GraphicsWidget):
Create a new LegendItem and anchor it over the internal ViewBox. Create a new LegendItem and anchor it over the internal ViewBox.
Plots will be automatically displayed in the legend if they Plots will be automatically displayed in the legend if they
are created with the 'name' argument. are created with the 'name' argument.
If a LegendItem has already been created using this method, that
item will be returned rather than creating a new one.
""" """
self.legend = LegendItem(size, offset) if self.legend is None:
self.legend.setParentItem(self.vb) self.legend = LegendItem(size, offset)
self.legend.setParentItem(self.vb)
return self.legend return self.legend
def scatterPlot(self, *args, **kargs): def scatterPlot(self, *args, **kargs):