diff --git a/pyqtgraph/graphicsItems/ErrorBarItem.py b/pyqtgraph/graphicsItems/ErrorBarItem.py index 986c5140..b79da6f7 100644 --- a/pyqtgraph/graphicsItems/ErrorBarItem.py +++ b/pyqtgraph/graphicsItems/ErrorBarItem.py @@ -23,6 +23,7 @@ class ErrorBarItem(GraphicsObject): beam=None, pen=None ) + self.setVisible(False) self.setData(**opts) def setData(self, **opts): @@ -45,6 +46,7 @@ class ErrorBarItem(GraphicsObject): This method was added in version 0.9.9. For prior versions, use setOpts. """ self.opts.update(opts) + self.setVisible(all(self.opts[ax] is not None for ax in ['x', 'y'])) self.path = None self.update() self.prepareGeometryChange() @@ -59,6 +61,7 @@ class ErrorBarItem(GraphicsObject): x, y = self.opts['x'], self.opts['y'] if x is None or y is None: + self.path = p return beam = self.opts['beam'] @@ -146,4 +149,4 @@ class ErrorBarItem(GraphicsObject): self.drawPath() return self.path.boundingRect() - \ No newline at end of file + diff --git a/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py new file mode 100644 index 00000000..4ee25e45 --- /dev/null +++ b/pyqtgraph/graphicsItems/tests/test_ErrorBarItem.py @@ -0,0 +1,37 @@ +import pyqtgraph as pg +import numpy as np + +app = pg.mkQApp() + + +def test_ErrorBarItem_defer_data(): + plot = pg.PlotWidget() + plot.show() + + # plot some data away from the origin to set the view rect + x = np.arange(5) + 10 + curve = pg.PlotCurveItem(x=x, y=x) + plot.addItem(curve) + app.processEvents() + r_no_ebi = plot.viewRect() + + # ErrorBarItem with no data shouldn't affect the view rect + err = pg.ErrorBarItem() + plot.addItem(err) + app.processEvents() + r_empty_ebi = plot.viewRect() + + assert r_no_ebi == r_empty_ebi + + err.setData(x=x, y=x, bottom=x, top=x) + app.processEvents() + r_ebi = plot.viewRect() + + assert r_empty_ebi != r_ebi + + # unset data, ErrorBarItem disappears and view rect goes back to original + err.setData(x=None, y=None) + app.processEvents() + r_clear_ebi = plot.viewRect() + + assert r_clear_ebi == r_no_ebi