diff options
Diffstat (limited to 'examples/plotWidget.py')
-rw-r--r-- | examples/plotWidget.py | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/examples/plotWidget.py b/examples/plotWidget.py index af64afb..ccd79e2 100644 --- a/examples/plotWidget.py +++ b/examples/plotWidget.py @@ -1,7 +1,6 @@ -# coding: utf-8 # /*########################################################################## # -# Copyright (c) 2017-2018 European Synchrotron Radiation Facility +# Copyright (c) 2017-2021 European Synchrotron Radiation Facility # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal @@ -43,10 +42,12 @@ import numpy from silx.gui import qt from silx.gui.plot import PlotWidget -from silx.gui.plot import tools # QToolbars to use with PlotWidget +from silx.gui.plot import tools # QToolbars to use with PlotWidget from silx.gui.plot import actions # QAction to use with PlotWidget from silx.gui.plot import PlotToolButtons # QToolButton to use with PlotWidget +from silx.gui.plot.tools.RulerToolButton import RulerToolButton from silx.gui.plot.ColorBar import ColorBarWidget +from silx.gui.plot.actions import control as control_actions class MyPlotWindow(qt.QMainWindow): @@ -64,7 +65,7 @@ class MyPlotWindow(qt.QMainWindow): # Make ColorBarWidget background white by changing its palette colorBar.setAutoFillBackground(True) palette = colorBar.palette() - palette.setColor(qt.QPalette.Background, qt.Qt.white) + palette.setColor(qt.QPalette.Window, qt.Qt.white) palette.setColor(qt.QPalette.Window, qt.Qt.white) colorBar.setPalette(palette) @@ -96,8 +97,7 @@ class MyPlotWindow(qt.QMainWindow): self.setCentralWidget(centralWidget) # Add ready to use toolbar with zoom and pan interaction mode buttons - interactionToolBar = tools.InteractiveModeToolBar( - parent=self, plot=self._plot) + interactionToolBar = tools.InteractiveModeToolBar(parent=self, plot=self._plot) self.addToolBar(interactionToolBar) # Add toolbar actions to activate keyboard shortcuts self.addActions(interactionToolBar.actions()) @@ -107,15 +107,24 @@ class MyPlotWindow(qt.QMainWindow): self.addToolBar(toolBar) # Add actions from silx.gui.plot.action to the toolbar - resetZoomAction = actions.control.ResetZoomAction( - parent=self, plot=self._plot) + resetZoomAction = actions.control.ResetZoomAction(parent=self, plot=self._plot) toolBar.addAction(resetZoomAction) # Add tool buttons from silx.gui.plot.PlotToolButtons aspectRatioButton = PlotToolButtons.AspectToolButton( - parent=self, plot=self._plot) + parent=self, plot=self._plot + ) toolBar.addWidget(aspectRatioButton) + # Add tool buttons from silx.gui.plot.PlotToolButtons + rulerButton = RulerToolButton( + parent=self, plot=self._plot + ) + toolBar.addWidget(rulerButton) + + action = control_actions.OpenGLAction(parent=toolBar, plot=self._plot) + toolBar.addAction(action) + # Add ready to use toolbar with copy, save and print buttons outputToolBar = tools.OutputToolBar(parent=self, plot=self._plot) self.addToolBar(outputToolBar) @@ -133,11 +142,10 @@ class MyPlotWindow(qt.QMainWindow): def showImage(self): plot = self.getPlotWidget() plot.clear() - plot.getDefaultColormap().setName('viridis') + plot.getDefaultColormap().setName("viridis") # Add an image to the plot - x = numpy.outer( - numpy.linspace(-10, 10, 200), numpy.linspace(-10, 5, 150)) + x = numpy.outer(numpy.linspace(-10, 10, 200), numpy.linspace(-10, 5, 150)) image = numpy.sin(x) / x plot.addImage(image) plot.resetZoom() @@ -145,7 +153,7 @@ class MyPlotWindow(qt.QMainWindow): def showScatter(self): plot = self.getPlotWidget() plot.clear() - plot.getDefaultColormap().setName('viridis') + plot.getDefaultColormap().setName("viridis") nbPoints = 50 x = numpy.random.rand(nbPoints) @@ -157,14 +165,13 @@ class MyPlotWindow(qt.QMainWindow): def showDelaunay(self): plot = self.getPlotWidget() plot.clear() - plot.getDefaultColormap().setName('viridis') + plot.getDefaultColormap().setName("viridis") nbPoints = 50 x = numpy.random.rand(nbPoints) y = numpy.random.rand(nbPoints) value = numpy.random.rand(nbPoints) - legend = plot.addScatter(x=x, y=y, value=value) - scatter = plot.getScatter(legend) + scatter = plot.addScatter(x=x, y=y, value=value) scatter.setVisualization("solid") plot.resetZoom() @@ -178,8 +185,8 @@ def main(): window.setAttribute(qt.Qt.WA_DeleteOnClose) window.show() window.showImage() - app.exec_() + app.exec() -if __name__ == '__main__': +if __name__ == "__main__": main() |