def testAddGetScatter(self): plot = PlotWidget(backend='none') # No curve scatter = plot._getItem(kind="scatter") self.assertIsNone(scatter) # No curve plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 0') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 1') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 2') plot._setActiveItem('scatter', 'scatter 0') # Active scatter active = plot._getActiveItem(kind='scatter') self.assertEqual(active.getLegend(), 'scatter 0') # check default values self.assertAlmostEqual(active.getSymbolSize(), active._DEFAULT_SYMBOL_SIZE) self.assertEqual(active.getSymbol(), "o") self.assertAlmostEqual(active.getAlpha(), 1.0) # modify parameters active.setSymbolSize(20.5) active.setSymbol("d") active.setAlpha(0.777) s0 = plot.getScatter("scatter 0") self.assertAlmostEqual(s0.getSymbolSize(), 20.5) self.assertEqual(s0.getSymbol(), "d") self.assertAlmostEqual(s0.getAlpha(), 0.777) scatter1 = plot._getItem(kind='scatter', legend='scatter 1') self.assertEqual(scatter1.getLegend(), 'scatter 1')
def testAddGetScatter(self): plot = PlotWidget(backend='none') # No curve scatter = plot._getItem(kind="scatter") self.assertIsNone(scatter) # No curve plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 0') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 1') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 2') plot._setActiveItem('scatter', 'scatter 0') # Active scatter active = plot._getActiveItem(kind='scatter') self.assertEqual(active.getName(), 'scatter 0') # check default values self.assertAlmostEqual(active.getSymbolSize(), active._DEFAULT_SYMBOL_SIZE) self.assertEqual(active.getSymbol(), "o") self.assertAlmostEqual(active.getAlpha(), 1.0) # modify parameters active.setSymbolSize(20.5) active.setSymbol("d") active.setAlpha(0.777) s0 = plot.getScatter("scatter 0") self.assertAlmostEqual(s0.getSymbolSize(), 20.5) self.assertEqual(s0.getSymbol(), "d") self.assertAlmostEqual(s0.getAlpha(), 0.777) scatter1 = plot._getItem(kind='scatter', legend='scatter 1') self.assertEqual(scatter1.getName(), 'scatter 1')
def testGetAllScatters(self): """PlotWidget.getAllImages test""" plot = PlotWidget(backend='none') items = plot.getItems() self.assertEqual(len(items), 0) plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 0') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 1') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 2') items = plot.getItems() self.assertEqual(len(items), 3) self.assertEqual(items[0].getName(), 'scatter 0') self.assertEqual(items[1].getName(), 'scatter 1') self.assertEqual(items[2].getName(), 'scatter 2')
def testGetAllScatters(self): """PlotWidget.getAllImages test""" plot = PlotWidget(backend='none') scatters = plot._getItems(kind='scatter') self.assertEqual(len(scatters), 0) plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 0') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 1') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 2') scatters = plot._getItems(kind='scatter') self.assertEqual(len(scatters), 3) self.assertEqual(scatters[0].getLegend(), 'scatter 0') self.assertEqual(scatters[2].getLegend(), 'scatter 2') scatters = plot._getItems(kind='scatter', just_legend=True) self.assertEqual(len(scatters), 3) self.assertEqual(list(scatters), ['scatter 0', 'scatter 1', 'scatter 2'])
def testGetAllScatters(self): """PlotWidget.getAllImages test""" plot = PlotWidget(backend='none') scatters = plot._getItems(kind='scatter') self.assertEqual(len(scatters), 0) plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 0') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 1') plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 2') scatters = plot._getItems(kind='scatter') self.assertEqual(len(scatters), 3) self.assertEqual(scatters[0].getLegend(), 'scatter 0') self.assertEqual(scatters[2].getLegend(), 'scatter 2') scatters = plot._getItems(kind='scatter', just_legend=True) self.assertEqual(len(scatters), 3) self.assertEqual(list(scatters), ['scatter 0', 'scatter 1', 'scatter 2'])
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_()
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_()