From 6648db031e2d578fe40dcd60de14123d0f92b7e5 Mon Sep 17 00:00:00 2001 From: Kevin Newman <47572615+kevinanewman@users.noreply.github.com> Date: Wed, 17 Jul 2019 08:37:16 -0400 Subject: [PATCH] Update LegendItem.py Propose adding a clear() method (or equivalent) for easier legend re-use with dynamically updated plots... --- pyqtgraph/graphicsItems/LegendItem.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pyqtgraph/graphicsItems/LegendItem.py b/pyqtgraph/graphicsItems/LegendItem.py index efb700a1..ce5bd883 100644 --- a/pyqtgraph/graphicsItems/LegendItem.py +++ b/pyqtgraph/graphicsItems/LegendItem.py @@ -101,6 +101,15 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): label.close() self.updateSize() # redraq box + def clear(self): + """ + Removes all items from the legend. + + Useful for reusing and dynamically updating charts and their legends. + """ + while self.items != []: + self.removeItem(self.items[0][1].text) + def updateSize(self): if self.size is not None: return