From c238be004ebb4a16917dc53cf5f53a6b52a4be1e Mon Sep 17 00:00:00 2001 From: Mikhail Terekhov Date: Thu, 15 Dec 2016 09:26:19 -0500 Subject: [PATCH 1/2] add test case for the PlotDataItem.clear() in stepMode --- pyqtgraph/graphicsItems/tests/test_PlotDataItem.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py index 8851a0a2..b506a654 100644 --- a/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py +++ b/pyqtgraph/graphicsItems/tests/test_PlotDataItem.py @@ -9,16 +9,16 @@ def test_fft(): x = np.linspace(0, 1, 1000) y = np.sin(2 * np.pi * f * x) pd = pg.PlotDataItem(x, y) - pd.setFftMode(True) + pd.setFftMode(True) x, y = pd.getData() assert abs(x[np.argmax(y)] - f) < 0.03 - + x = np.linspace(0, 1, 1001) y = np.sin(2 * np.pi * f * x) pd.setData(x, y) x, y = pd.getData() assert abs(x[np.argmax(y)]- f) < 0.03 - + pd.setLogMode(True, False) x, y = pd.getData() assert abs(x[np.argmax(y)] - np.log10(f)) < 0.01 @@ -58,3 +58,9 @@ def test_clear(): assert pdi.xData == None assert pdi.yData == None + +def test_clear_in_step_mode(): + w = pg.PlotWidget() + c = pg.PlotDataItem([1,4,2,3], [5,7,6], stepMode=True) + w.addItem(c) + c.clear() From b13062f081464d6950990d7e3add969e43e7d934 Mon Sep 17 00:00:00 2001 From: Mikhail Terekhov Date: Wed, 14 Dec 2016 22:39:39 -0500 Subject: [PATCH 2/2] In PlotDataItem.clear() use corresponding curve.clear() and scatter.clear() Otherwise when stepMode is True curve.setData([]) causes exception: "len(X) must be len(Y)+1 ..." --- pyqtgraph/graphicsItems/PlotDataItem.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyqtgraph/graphicsItems/PlotDataItem.py b/pyqtgraph/graphicsItems/PlotDataItem.py index 2faa9ac1..1bf48f5d 100644 --- a/pyqtgraph/graphicsItems/PlotDataItem.py +++ b/pyqtgraph/graphicsItems/PlotDataItem.py @@ -627,9 +627,9 @@ class PlotDataItem(GraphicsObject): #self.yClean = None self.xDisp = None self.yDisp = None - self.curve.setData([]) - self.scatter.setData([]) - + self.curve.clear() + self.scatter.clear() + def appendData(self, *args, **kargs): pass