def _initColorBar(self): """Create the ColorBarWidget and add it to the PlotWidget""" # Add a colorbar on the right side colorBar = ColorBarWidget(parent=self, plot=self) # 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) colorBar.setPalette(palette) # Add the ColorBarWidget by changing PlotWidget's central widget gridLayout = qt.QGridLayout() gridLayout.setSpacing(0) gridLayout.setContentsMargins(0, 0, 0, 0) plot = self.getWidgetHandle() # Get the widget rendering the plot gridLayout.addWidget(plot, 0, 0) gridLayout.addWidget(colorBar, 0, 1) gridLayout.setRowStretch(0, 1) gridLayout.setColumnStretch(0, 1) centralWidget = qt.QWidget() centralWidget.setLayout(gridLayout) self.setCentralWidget(centralWidget)
def __init__(self, parent=None): super(MyPlotWindow, self).__init__(parent) # Create a PlotWidget self._plot = PlotWidget(parent=self) # Create a colorbar linked with the PlotWidget colorBar = ColorBarWidget(parent=self, plot=self._plot) # 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) colorBar.setPalette(palette) # Combine the ColorBarWidget and the PlotWidget as # this QMainWindow's central widget gridLayout = qt.QGridLayout() gridLayout.setSpacing(0) gridLayout.setContentsMargins(0, 0, 0, 0) gridLayout.addWidget(self._plot, 0, 0) gridLayout.addWidget(colorBar, 0, 1) gridLayout.setRowStretch(0, 1) gridLayout.setColumnStretch(0, 1) centralWidget = qt.QWidget(self) centralWidget.setLayout(gridLayout) self.setCentralWidget(centralWidget) # Add ready to use toolbar with zoom and pan interaction mode buttons interactionToolBar = tools.InteractiveModeToolBar(parent=self, plot=self._plot) self.addToolBar(interactionToolBar) # Add toolbar actions to activate keyboard shortcuts self.addActions(interactionToolBar.actions()) # Add a new toolbar toolBar = qt.QToolBar("Plot Tools", self) self.addToolBar(toolBar) # Add actions from silx.gui.plot.action to the toolbar 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) toolBar.addWidget(aspectRatioButton) # Add ready to use toolbar with copy, save and print buttons outputToolBar = tools.OutputToolBar(parent=self, plot=self._plot) self.addToolBar(outputToolBar) # Add toolbar actions to activate keyboard shortcuts self.addActions(outputToolBar.actions()) # Add limits tool bar from silx.gui.plot.PlotTools limitsToolBar = tools.LimitsToolBar(parent=self, plot=self._plot) self.addToolBar(qt.Qt.BottomToolBarArea, limitsToolBar)
def __init__(self, parent=None): super(MyPlotWindow, self).__init__(parent) # Create a PlotWidget self._plot = PlotWidget(parent=self) # Create a colorbar linked with the PlotWidget colorBar = ColorBarWidget(parent=self, plot=self._plot) # 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) colorBar.setPalette(palette) # Combine the ColorBarWidget and the PlotWidget as # this QMainWindow's central widget gridLayout = qt.QGridLayout() gridLayout.setSpacing(0) gridLayout.setContentsMargins(0, 0, 0, 0) gridLayout.addWidget(self._plot, 0, 0) gridLayout.addWidget(colorBar, 0, 1) gridLayout.setRowStretch(0, 1) gridLayout.setColumnStretch(0, 1) centralWidget = qt.QWidget(self) centralWidget.setLayout(gridLayout) self.setCentralWidget(centralWidget) # Add ready to use toolbar with zoom and pan interaction mode buttons interactionToolBar = tools.InteractiveModeToolBar( parent=self, plot=self._plot) self.addToolBar(interactionToolBar) # Add toolbar actions to activate keyboard shortcuts self.addActions(interactionToolBar.actions()) # Add a new toolbar toolBar = qt.QToolBar("Plot Tools", self) self.addToolBar(toolBar) # Add actions from silx.gui.plot.action to the toolbar 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) toolBar.addWidget(aspectRatioButton) # Add ready to use toolbar with copy, save and print buttons outputToolBar = tools.OutputToolBar(parent=self, plot=self._plot) self.addToolBar(outputToolBar) # Add toolbar actions to activate keyboard shortcuts self.addActions(outputToolBar.actions()) # Add limits tool bar from silx.gui.plot.PlotTools limitsToolBar = tools.LimitsToolBar(parent=self, plot=self._plot) self.addToolBar(qt.Qt.BottomToolBarArea, limitsToolBar)
def __init__(self, parent=None): super(ColormapDialogExample, self).__init__(parent) self.setWindowTitle("Colormap dialog example") self.colormap1 = Colormap("viridis") self.colormap2 = Colormap("gray") self.colorBar = ColorBarWidget(self) self.colorDialogs = [] options = qt.QWidget(self) options.setLayout(qt.QVBoxLayout()) self.createOptions(options.layout()) mainWidget = qt.QWidget(self) mainWidget.setLayout(qt.QHBoxLayout()) mainWidget.layout().addWidget(options) mainWidget.layout().addWidget(self.colorBar) self.mainWidget = mainWidget self.setCentralWidget(mainWidget) self.createColorDialog()
def __init__(self, parent=None): super(ColormapDialogExample, self).__init__(parent) self.setWindowTitle("Colormap dialog example") self.colormap1 = Colormap("viridis") self.colormap2 = Colormap("gray") self.colorBar = ColorBarWidget(self) self.colorDialogs = [] options = qt.QWidget(self) options.setLayout(qt.QVBoxLayout()) self.createOptions(options.layout()) mainWidget = qt.QWidget(self) mainWidget.setLayout(qt.QHBoxLayout()) mainWidget.layout().addWidget(options) mainWidget.layout().addWidget(self.colorBar) self.mainWidget = mainWidget self.setCentralWidget(mainWidget) self.createColorDialog()
def testEmptyColorBar(self): colorBar = ColorBarWidget(parent=None) colorBar.show() self.qWaitForWindowExposed(colorBar)
class ColorBarShower(qt.QWidget): """ Simple widget displaying n image with different colormap, an active colorbar """ def __init__(self): qt.QWidget.__init__(self) self.setLayout(qt.QHBoxLayout()) self._buildActiveImageSelector() self.layout().addWidget(self.image_selector) self._buildPlot() self.layout().addWidget(self.plot) self._buildColorbar() self.layout().addWidget(self.colorbar) self._buildColormapEditors() self.layout().addWidget(self._cmpEditor) # connect radio button with the plot self.image_selector._qr1.toggled.connect(self.activateImageChanged) self.image_selector._qr2.toggled.connect(self.activateImageChanged) self.image_selector._qr3.toggled.connect(self.activateImageChanged) self.image_selector._qr4.toggled.connect(self.activateImageChanged) self.image_selector._qr5.toggled.connect(self.activateImageChanged) self.image_selector._qr6.toggled.connect(self.activateImageChanged) def _buildActiveImageSelector(self): """Build the image selector widget""" self.image_selector = qt.QGroupBox(parent=self) self.image_selector.setLayout(qt.QVBoxLayout()) self.image_selector._qr1 = qt.QRadioButton('image1') self.image_selector._qr1.setChecked(True) self.image_selector._qr2 = qt.QRadioButton('image2') self.image_selector._qr3 = qt.QRadioButton('image3') self.image_selector._qr4 = qt.QRadioButton('image4') self.image_selector._qr5 = qt.QRadioButton('image5') self.image_selector._qr6 = qt.QRadioButton('image6') self.image_selector.layout().addWidget(self.image_selector._qr6) self.image_selector.layout().addWidget(self.image_selector._qr5) self.image_selector.layout().addWidget(self.image_selector._qr4) self.image_selector.layout().addWidget(self.image_selector._qr3) self.image_selector.layout().addWidget(self.image_selector._qr2) self.image_selector.layout().addWidget(self.image_selector._qr1) def activateImageChanged(self): if self.image_selector._qr1.isChecked(): self.plot.setActiveImage('image1') if self.image_selector._qr2.isChecked(): self.plot.setActiveImage('image2') if self.image_selector._qr3.isChecked(): self.plot.setActiveImage('image3') if self.image_selector._qr4.isChecked(): self.plot.setActiveImage('image4') if self.image_selector._qr5.isChecked(): self.plot.setActiveImage('image5') if self.image_selector._qr6.isChecked(): self.plot.setActiveImage('image6') def _buildColorbar(self): self.colorbar = ColorBarWidget(parent=self) self.colorbar.setPlot(self.plot) def _buildPlot(self): image1 = numpy.exp(numpy.random.rand(IMG_WIDTH, IMG_WIDTH) * 10) image2 = numpy.linspace(-100, 1000, IMG_WIDTH * IMG_WIDTH).reshape( IMG_WIDTH, IMG_WIDTH) image3 = numpy.linspace(-1, 1, IMG_WIDTH * IMG_WIDTH).reshape( IMG_WIDTH, IMG_WIDTH) image4 = numpy.linspace(-20, 50, IMG_WIDTH * IMG_WIDTH).reshape( IMG_WIDTH, IMG_WIDTH) image5 = image3 image6 = image4 # viridis colormap self.colormap1 = Colormap.Colormap(name='green', normalization='log', vmin=None, vmax=None) self.plot = PlotWidget(parent=self) self.plot.addImage(data=image1, origin=(0, 0), legend='image1', colormap=self.colormap1) self.plot.addImage(data=image2, origin=(100, 0), legend='image2', colormap=self.colormap1) # red colormap self.colormap2 = Colormap.Colormap(name='red', normalization='linear', vmin=None, vmax=None) self.plot.addImage(data=image3, origin=(0, 100), legend='image3', colormap=self.colormap2) self.plot.addImage(data=image4, origin=(100, 100), legend='image4', colormap=self.colormap2) # gray colormap self.colormap3 = Colormap.Colormap(name='gray', normalization='linear', vmin=1.0, vmax=20.0) self.plot.addImage(data=image5, origin=(0, 200), legend='image5', colormap=self.colormap3) self.plot.addImage(data=image6, origin=(100, 200), legend='image6', colormap=self.colormap3) def _buildColormapEditors(self): self._cmpEditor = qt.QWidget(parent=self) self._cmpEditor.setLayout(qt.QVBoxLayout()) self._cmpEditor.layout().addWidget(_ColormapEditor(self.colormap3)) self._cmpEditor.layout().addWidget(_ColormapEditor(self.colormap2)) self._cmpEditor.layout().addWidget(_ColormapEditor(self.colormap1))
def _buildColorbar(self): self.colorbar = ColorBarWidget(parent=self) self.colorbar.setPlot(self.plot)
def testEmptyColorBar(self): colorBar = ColorBarWidget(parent=None) colorBar.show() self.qWaitForWindowExposed(colorBar)
class ColormapDialogExample(qt.QMainWindow): """PlotWidget with an ad hoc toolbar and a colorbar""" def __init__(self, parent=None): super(ColormapDialogExample, self).__init__(parent) self.setWindowTitle("Colormap dialog example") self.colormap1 = Colormap("viridis") self.colormap2 = Colormap("gray") self.colorBar = ColorBarWidget(self) self.colorDialogs = [] options = qt.QWidget(self) options.setLayout(qt.QVBoxLayout()) self.createOptions(options.layout()) mainWidget = qt.QWidget(self) mainWidget.setLayout(qt.QHBoxLayout()) mainWidget.layout().addWidget(options) mainWidget.layout().addWidget(self.colorBar) self.mainWidget = mainWidget self.setCentralWidget(mainWidget) self.createColorDialog() def createOptions(self, layout): button = qt.QPushButton("Create a new dialog") button.clicked.connect(self.createColorDialog) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set editable") button.clicked.connect(self.setEditable) layout.addWidget(button) button = qt.QPushButton("Set non-editable") button.clicked.connect(self.setNonEditable) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no colormap") button.clicked.connect(self.setNoColormap) layout.addWidget(button) button = qt.QPushButton("Set colormap 1") button.clicked.connect(self.setColormap1) layout.addWidget(button) button = qt.QPushButton("Set colormap 2") button.clicked.connect(self.setColormap2) layout.addWidget(button) button = qt.QPushButton("Create new colormap") button.clicked.connect(self.setNewColormap) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no histogram") button.clicked.connect(self.setNoHistogram) layout.addWidget(button) button = qt.QPushButton("Set positive histogram") button.clicked.connect(self.setPositiveHistogram) layout.addWidget(button) button = qt.QPushButton("Set neg-pos histogram") button.clicked.connect(self.setNegPosHistogram) layout.addWidget(button) button = qt.QPushButton("Set negative histogram") button.clicked.connect(self.setNegativeHistogram) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no range") button.clicked.connect(self.setNoRange) layout.addWidget(button) button = qt.QPushButton("Set positive range") button.clicked.connect(self.setPositiveRange) layout.addWidget(button) button = qt.QPushButton("Set neg-pos range") button.clicked.connect(self.setNegPosRange) layout.addWidget(button) button = qt.QPushButton("Set negative range") button.clicked.connect(self.setNegativeRange) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no data") button.clicked.connect(self.setNoData) layout.addWidget(button) button = qt.QPushButton("Set shepp logan phantom") button.clicked.connect(self.setSheppLoganPhantom) layout.addWidget(button) button = qt.QPushButton("Set data with non finite") button.clicked.connect(self.setDataWithNonFinite) layout.addWidget(button) layout.addStretch() def createColorDialog(self): newDialog = ColormapDialog(self) newDialog.finished.connect( functools.partial(self.removeColorDialog, newDialog)) self.colorDialogs.append(newDialog) self.mainWidget.layout().addWidget(newDialog) def removeColorDialog(self, dialog): self.colorDialogs.remove(dialog) def setNoColormap(self): self.colorBar.setColormap(None) for dialog in self.colorDialogs: dialog.setColormap(None) def setColormap1(self): self.colorBar.setColormap(self.colormap1) for dialog in self.colorDialogs: dialog.setColormap(self.colormap1) def setColormap2(self): self.colorBar.setColormap(self.colormap2) for dialog in self.colorDialogs: dialog.setColormap(self.colormap2) def setEditable(self): for dialog in self.colorDialogs: colormap = dialog.getColormap() if colormap is not None: colormap.setEditable(True) def setNonEditable(self): for dialog in self.colorDialogs: colormap = dialog.getColormap() if colormap is not None: colormap.setEditable(False) def setNewColormap(self): self.colormap = Colormap("inferno") self.colorBar.setColormap(self.colormap) for dialog in self.colorDialogs: dialog.setColormap(self.colormap) def setNoHistogram(self): for dialog in self.colorDialogs: dialog.setHistogram() def setPositiveHistogram(self): histo = [5, 10, 50, 10, 5] pos = 1 edges = list(range(pos, pos + len(histo))) for dialog in self.colorDialogs: dialog.setHistogram(histo, edges) def setNegPosHistogram(self): histo = [5, 10, 50, 10, 5] pos = -2 edges = list(range(pos, pos + len(histo))) for dialog in self.colorDialogs: dialog.setHistogram(histo, edges) def setNegativeHistogram(self): histo = [5, 10, 50, 10, 5] pos = -30 edges = list(range(pos, pos + len(histo))) for dialog in self.colorDialogs: dialog.setHistogram(histo, edges) def setNoRange(self): for dialog in self.colorDialogs: dialog.setDataRange() def setPositiveRange(self): for dialog in self.colorDialogs: dialog.setDataRange(1, 1, 10) def setNegPosRange(self): for dialog in self.colorDialogs: dialog.setDataRange(-10, 1, 10) def setNegativeRange(self): for dialog in self.colorDialogs: dialog.setDataRange(-10, float("nan"), -1) def setNoData(self): for dialog in self.colorDialogs: dialog.setData(None) def setSheppLoganPhantom(self): from silx.image import phantomgenerator data = phantomgenerator.PhantomGenerator.get2DPhantomSheppLogan(256) data = data * 1000 if scipy is not None: from scipy import ndimage data = ndimage.gaussian_filter(data, sigma=20) data = numpy.random.poisson(data) self.data = data for dialog in self.colorDialogs: dialog.setData(data) def setDataWithNonFinite(self): from silx.image import phantomgenerator data = phantomgenerator.PhantomGenerator.get2DPhantomSheppLogan(256) data = data * 1000 if scipy is not None: from scipy import ndimage data = ndimage.gaussian_filter(data, sigma=20) data = numpy.random.poisson(data) data[10] = float("nan") data[50] = float("+inf") data[100] = float("-inf") self.data = data for dialog in self.colorDialogs: dialog.setData(data)
class ColormapDialogExample(qt.QMainWindow): """PlotWidget with an ad hoc toolbar and a colorbar""" def __init__(self, parent=None): super(ColormapDialogExample, self).__init__(parent) self.setWindowTitle("Colormap dialog example") self.colormap1 = Colormap("viridis") self.colormap2 = Colormap("gray") self.colorBar = ColorBarWidget(self) self.colorDialogs = [] options = qt.QWidget(self) options.setLayout(qt.QVBoxLayout()) self.createOptions(options.layout()) mainWidget = qt.QWidget(self) mainWidget.setLayout(qt.QHBoxLayout()) mainWidget.layout().addWidget(options) mainWidget.layout().addWidget(self.colorBar) self.mainWidget = mainWidget self.setCentralWidget(mainWidget) self.createColorDialog() def createOptions(self, layout): button = qt.QPushButton("Create a new dialog") button.clicked.connect(self.createColorDialog) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set editable") button.clicked.connect(self.setEditable) layout.addWidget(button) button = qt.QPushButton("Set non-editable") button.clicked.connect(self.setNonEditable) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no colormap") button.clicked.connect(self.setNoColormap) layout.addWidget(button) button = qt.QPushButton("Set colormap 1") button.clicked.connect(self.setColormap1) layout.addWidget(button) button = qt.QPushButton("Set colormap 2") button.clicked.connect(self.setColormap2) layout.addWidget(button) button = qt.QPushButton("Create new colormap") button.clicked.connect(self.setNewColormap) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no histogram") button.clicked.connect(self.setNoHistogram) layout.addWidget(button) button = qt.QPushButton("Set positive histogram") button.clicked.connect(self.setPositiveHistogram) layout.addWidget(button) button = qt.QPushButton("Set neg-pos histogram") button.clicked.connect(self.setNegPosHistogram) layout.addWidget(button) button = qt.QPushButton("Set negative histogram") button.clicked.connect(self.setNegativeHistogram) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no range") button.clicked.connect(self.setNoRange) layout.addWidget(button) button = qt.QPushButton("Set positive range") button.clicked.connect(self.setPositiveRange) layout.addWidget(button) button = qt.QPushButton("Set neg-pos range") button.clicked.connect(self.setNegPosRange) layout.addWidget(button) button = qt.QPushButton("Set negative range") button.clicked.connect(self.setNegativeRange) layout.addWidget(button) layout.addSpacing(10) button = qt.QPushButton("Set no data") button.clicked.connect(self.setNoData) layout.addWidget(button) button = qt.QPushButton("Set shepp logan phantom") button.clicked.connect(self.setSheppLoganPhantom) layout.addWidget(button) button = qt.QPushButton("Set data with non finite") button.clicked.connect(self.setDataWithNonFinite) layout.addWidget(button) layout.addStretch() def createColorDialog(self): newDialog = ColormapDialog(self) newDialog.finished.connect(functools.partial(self.removeColorDialog, newDialog)) self.colorDialogs.append(newDialog) self.mainWidget.layout().addWidget(newDialog) def removeColorDialog(self, dialog): self.colorDialogs.remove(dialog) def setNoColormap(self): self.colorBar.setColormap(None) for dialog in self.colorDialogs: dialog.setColormap(None) def setColormap1(self): self.colorBar.setColormap(self.colormap1) for dialog in self.colorDialogs: dialog.setColormap(self.colormap1) def setColormap2(self): self.colorBar.setColormap(self.colormap2) for dialog in self.colorDialogs: dialog.setColormap(self.colormap2) def setEditable(self): for dialog in self.colorDialogs: colormap = dialog.getColormap() if colormap is not None: colormap.setEditable(True) def setNonEditable(self): for dialog in self.colorDialogs: colormap = dialog.getColormap() if colormap is not None: colormap.setEditable(False) def setNewColormap(self): self.colormap = Colormap("inferno") self.colorBar.setColormap(self.colormap) for dialog in self.colorDialogs: dialog.setColormap(self.colormap) def setNoHistogram(self): for dialog in self.colorDialogs: dialog.setHistogram() def setPositiveHistogram(self): histo = [5, 10, 50, 10, 5] pos = 1 edges = list(range(pos, pos + len(histo))) for dialog in self.colorDialogs: dialog.setHistogram(histo, edges) def setNegPosHistogram(self): histo = [5, 10, 50, 10, 5] pos = -2 edges = list(range(pos, pos + len(histo))) for dialog in self.colorDialogs: dialog.setHistogram(histo, edges) def setNegativeHistogram(self): histo = [5, 10, 50, 10, 5] pos = -30 edges = list(range(pos, pos + len(histo))) for dialog in self.colorDialogs: dialog.setHistogram(histo, edges) def setNoRange(self): for dialog in self.colorDialogs: dialog.setDataRange() def setPositiveRange(self): for dialog in self.colorDialogs: dialog.setDataRange(1, 1, 10) def setNegPosRange(self): for dialog in self.colorDialogs: dialog.setDataRange(-10, 1, 10) def setNegativeRange(self): for dialog in self.colorDialogs: dialog.setDataRange(-10, float("nan"), -1) def setNoData(self): for dialog in self.colorDialogs: dialog.setData(None) def setSheppLoganPhantom(self): from silx.image import phantomgenerator data = phantomgenerator.PhantomGenerator.get2DPhantomSheppLogan(256) data = data * 1000 if scipy is not None: from scipy import ndimage data = ndimage.gaussian_filter(data, sigma=20) data = numpy.random.poisson(data) self.data = data for dialog in self.colorDialogs: dialog.setData(data) def setDataWithNonFinite(self): from silx.image import phantomgenerator data = phantomgenerator.PhantomGenerator.get2DPhantomSheppLogan(256) data = data * 1000 if scipy is not None: from scipy import ndimage data = ndimage.gaussian_filter(data, sigma=20) data = numpy.random.poisson(data) data[10] = float("nan") data[50] = float("+inf") data[100] = float("-inf") self.data = data for dialog in self.colorDialogs: dialog.setData(data)