def testDataRangeLeftRight(self): """right+left axis range""" plot = PlotWidget(backend='none') xData_l = numpy.arange(10) - 0.9 # range : -0.9 , 8.1 yData_l = numpy.arange(10) - 1.9 # range : -1.9 , 7.1 plot.addCurve(x=xData_l, y=yData_l, legend='plot_l', yaxis='left') xData_r = numpy.arange(10) - 4.9 # range : -4.9 , 4.1 yData_r = numpy.arange(10) - 6.9 # range : -6.9 , 2.1 plot.addCurve(x=xData_r, y=yData_r, legend='plot_r', yaxis='right') for logX, logY in ((False, False), (True, False), (True, True), (False, True), (False, False)): with self.subTest(logX=logX, logY=logY): plot.getXAxis()._setLogarithmic(logX) plot.getYAxis()._setLogarithmic(logY) dataRange = plot.getDataRange() xRangeL, yRangeL = self._getRanges([xData_l, yData_l], [logX, logY]) xRangeR, yRangeR = self._getRanges([xData_r, yData_r], [logX, logY]) xRangeLR = self._getRangesMinmax([xRangeL, xRangeR]) self.assertSequenceEqual(dataRange.x, xRangeLR) self.assertSequenceEqual(dataRange.y, yRangeL) self.assertSequenceEqual(dataRange.yright, yRangeR)
def testGetCurveOldApi(self): """old API PlotWidget.getCurve and Plot.getActiveCurve tests""" plot = PlotWidget(backend='none') # No curve curve = plot.getCurve() self.assertIsNone(curve) # No curve plot.setActiveCurveHandling(True) x = numpy.arange(10.).astype(numpy.float32) y = x * x plot.addCurve(x=x, y=y, legend='curve 0', info=["whatever"]) plot.addCurve(x=x, y=2 * x, legend='curve 1', info="anything") plot.setActiveCurve('curve 0') # Active curve (4 elements) xOut, yOut, legend, info = plot.getActiveCurve()[:4] self.assertEqual(legend, 'curve 0') self.assertTrue(numpy.allclose(xOut, x), 'curve 0 wrong x data') self.assertTrue(numpy.allclose(yOut, y), 'curve 0 wrong y data') # Active curve (5 elements) xOut, yOut, legend, info, params = plot.getCurve("curve 1") self.assertEqual(legend, 'curve 1') self.assertEqual(info, 'anything') self.assertTrue(numpy.allclose(xOut, x), 'curve 1 wrong x data') self.assertTrue(numpy.allclose(yOut, 2 * x), 'curve 1 wrong y data')
def testGetCurveOldApi(self): """old API PlotWidget.getCurve and Plot.getActiveCurve tests""" plot = PlotWidget(backend='none') # No curve curve = plot.getCurve() self.assertIsNone(curve) # No curve plot.setActiveCurveHandling(True) x = numpy.arange(10.).astype(numpy.float32) y = x * x plot.addCurve(x=x, y=y, legend='curve 0', info=["whatever"]) plot.addCurve(x=x, y=2*x, legend='curve 1', info="anything") plot.setActiveCurve('curve 0') # Active curve (4 elements) xOut, yOut, legend, info = plot.getActiveCurve()[:4] self.assertEqual(legend, 'curve 0') self.assertTrue(numpy.allclose(xOut, x), 'curve 0 wrong x data') self.assertTrue(numpy.allclose(yOut, y), 'curve 0 wrong y data') # Active curve (5 elements) xOut, yOut, legend, info, params = plot.getCurve("curve 1") self.assertEqual(legend, 'curve 1') self.assertEqual(info, 'anything') self.assertTrue(numpy.allclose(xOut, x), 'curve 1 wrong x data') self.assertTrue(numpy.allclose(yOut, 2 * x), 'curve 1 wrong y data')
def testDataRangeRight(self): """right axis range""" plot = PlotWidget(backend='none') xData = numpy.arange(10) - 4.9 # range : -4.9 , 4.1 yData = numpy.arange(10) - 6.9 # range : -6.9 , 2.1 plot.addCurve(x=xData, y=yData, legend='plot_0', yaxis='right') for logX, logY in ((False, False), (True, False), (True, True), (False, True), (False, False)): with self.subTest(logX=logX, logY=logY): plot.getXAxis()._setLogarithmic(logX) plot.getYAxis()._setLogarithmic(logY) dataRange = plot.getDataRange() xRange, yRange = self._getRanges([xData, yData], [logX, logY]) self.assertSequenceEqual(dataRange.x, xRange) self.assertIsNone(dataRange.y) self.assertSequenceEqual(dataRange.yright, yRange)
def testAddNoRemove(self): """add objects to the Plot""" plot = PlotWidget(backend='none') plot.addCurve(x=(1, 2, 3), y=(3, 2, 1)) plot.addImage(numpy.arange(100.).reshape(10, -1)) plot.addItem( numpy.array((1., 10.)), numpy.array((10., 10.)), shape="rectangle") plot.addXMarker(10.)
def testDataRangeCurveImage(self): """right+left+image axis range""" # overlapping ranges : # image sets x min and y max # plot_left sets y min # plot_right sets x max (and yright) plot = PlotWidget(backend='none') origin = (-10, 5) scale = (3., 8.) image = numpy.arange(100.).reshape(20, 5) plot.addImage(image, origin=origin, scale=scale, legend='image') xData_l = numpy.arange(10) - 0.9 # range : -0.9 , 8.1 yData_l = numpy.arange(10) - 1.9 # range : -1.9 , 7.1 plot.addCurve(x=xData_l, y=yData_l, legend='plot_l', yaxis='left') xData_r = numpy.arange(10) + 4.1 # range : 4.1 , 13.1 yData_r = numpy.arange(10) - 0.9 # range : -0.9 , 8.1 plot.addCurve(x=xData_r, y=yData_r, legend='plot_r', yaxis='right') imgXRange = numpy.array([0., image.shape[1] * scale[0]]) + origin[0] imgYRange = numpy.array([0., image.shape[0] * scale[1]]) + origin[1] for logX, logY in ((False, False), (True, False), (True, True), (False, True), (False, False)): with self.subTest(logX=logX, logY=logY): plot.getXAxis()._setLogarithmic(logX) plot.getYAxis()._setLogarithmic(logY) dataRange = plot.getDataRange() xRangeL, yRangeL = self._getRanges([xData_l, yData_l], [logX, logY]) xRangeR, yRangeR = self._getRanges([xData_r, yData_r], [logX, logY]) if logX or logY: xRangeLR = self._getRangesMinmax([xRangeL, xRangeR]) else: xRangeLR = self._getRangesMinmax([xRangeL, xRangeR, imgXRange]) yRangeL = self._getRangesMinmax([yRangeL, imgYRange]) self.assertSequenceEqual(dataRange.x, xRangeLR) self.assertSequenceEqual(dataRange.y, yRangeL) self.assertSequenceEqual(dataRange.yright, yRangeR)
def testAddNoRemove(self): """add objects to the Plot""" plot = PlotWidget(backend='none') plot.addCurve(x=(1, 2, 3), y=(3, 2, 1)) plot.addImage(numpy.arange(100.).reshape(10, -1)) plot.addShape(numpy.array((1., 10.)), numpy.array((10., 10.)), shape="rectangle") plot.addXMarker(10.)
def testDataRangeHiddenCurve(self): """curves with a hidden curve""" plot = PlotWidget(backend='none') plot.addCurve((0, 1), (0, 1), legend='shown') plot.addCurve((0, 1, 2), (5, 5, 5), legend='hidden') range1 = plot.getDataRange() self.assertEqual(range1.x, (0, 2)) self.assertEqual(range1.y, (0, 5)) plot.hideCurve('hidden') range2 = plot.getDataRange() self.assertEqual(range2.x, (0, 1)) self.assertEqual(range2.y, (0, 1))
def testGetCurve(self): """PlotWidget.getCurve and Plot.getActiveCurve tests""" plot = PlotWidget(backend='none') # No curve curve = plot.getCurve() self.assertIsNone(curve) # No curve plot.setActiveCurveHandling(True) plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 0') plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 1') plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 2') plot.setActiveCurve('curve 0') # Active curve active = plot.getActiveCurve() self.assertEqual(active.getLegend(), 'curve 0') curve = plot.getCurve() self.assertEqual(curve.getLegend(), 'curve 0') # No active curve and curves plot.setActiveCurveHandling(False) active = plot.getActiveCurve() self.assertIsNone(active) # No active curve curve = plot.getCurve() self.assertEqual(curve.getLegend(), 'curve 2') # Last added curve # Last curve hidden plot.hideCurve('curve 2', True) curve = plot.getCurve() self.assertEqual(curve.getLegend(), 'curve 1') # Last added curve # All curves hidden plot.hideCurve('curve 1', True) plot.hideCurve('curve 0', True) curve = plot.getCurve() self.assertIsNone(curve)
"""This example illustrates how to use a :class:`ItemsSelectionDialog` widget associated with a :class:`~silx.gui.plot.PlotWidget`. """ __authors__ = ["P. Knobel"] __license__ = "MIT" __date__ = "28/06/2017" from silx.gui import qt from silx.gui.plot.PlotWidget import PlotWidget from silx.gui.plot.ItemsSelectionDialog import ItemsSelectionDialog app = qt.QApplication([]) pw = PlotWidget() pw.addCurve([0, 1, 2], [3, 2, 1], "A curve") pw.addScatter([0, 1, 2.5], [3, 2.5, 0.9], [8, 9, 72], "A scatter") pw.addHistogram([0, 1, 2.5], [0, 1, 2, 3], "A histogram") pw.addImage([[0, 1, 2], [3, 2, 1]], "An image") pw.show() isd = ItemsSelectionDialog(plot=pw) isd.setItemsSelectionMode(qt.QTableWidget.ExtendedSelection) result = isd.exec_() if result: for item in isd.getSelectedItems(): print(item.getName(), type(item)) else: print("Selection cancelled") app.exec_()
"""This example illustrates how to use a :class:`ItemsSelectionDialog` widget associated with a :class:`~silx.gui.plot.PlotWidget`. """ __authors__ = ["P. Knobel"] __license__ = "MIT" __date__ = "28/06/2017" from silx.gui import qt from silx.gui.plot.PlotWidget import PlotWidget from silx.gui.plot.ItemsSelectionDialog import ItemsSelectionDialog app = qt.QApplication([]) pw = PlotWidget() pw.addCurve([0, 1, 2], [3, 2, 1], "A curve") pw.addScatter([0, 1, 2.5], [3, 2.5, 0.9], [8, 9, 72], "A scatter") pw.addHistogram([0, 1, 2.5], [0, 1, 2, 3], "A histogram") pw.addImage([[0, 1, 2], [3, 2, 1]], "An image") pw.show() isd = ItemsSelectionDialog(plot=pw) isd.setItemsSelectionMode(qt.QTableWidget.ExtendedSelection) result = isd.exec_() if result: for item in isd.getSelectedItems(): print(item.getLegend(), type(item)) else: print("Selection cancelled") app.exec_()