diff --git a/src/silx/gui/plot/PlotWindow.py b/src/silx/gui/plot/PlotWindow.py index 7f330478fc..304b1c9267 100644 --- a/src/silx/gui/plot/PlotWindow.py +++ b/src/silx/gui/plot/PlotWindow.py @@ -183,6 +183,12 @@ def __init__( self.yAxisLogarithmicAction.setVisible(logScale) self.addAction(self.yAxisLogarithmicAction) + self.yAxisArcsinhAction = self.group.addAction( + actions.control.YAxisArcsinhAction(self, parent=self) + ) + self.yAxisArcsinhAction.setVisible(logScale) + self.addAction(self.yAxisArcsinhAction) + self.gridAction = self.group.addAction( actions.control.GridAction(self, gridMode="both", parent=self) ) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index 210166b7d8..6a81640fd6 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -282,6 +282,35 @@ def _actionTriggered(self, checked=False): scale = self.axis.LOGARITHMIC if checked else self.axis.LINEAR self.axis.setScale(scale) + +class YAxisArcsinhAction(PlotAction): + """QAction controlling Y axis arcsinh scale on a :class:`.PlotWidget`. + + :param plot: :class:`.PlotWidget` instance on which to operate + :param parent: See :class:`QAction` + """ + + def __init__(self, plot, parent=None): + super().__init__( + plot, + icon="plot-yasinh", + text="Arcsinh scale", + tooltip="Arcsinh y-axis when checked", + triggered=self._actionTriggered, + checkable=True, + parent=parent, + ) + self.axis = plot.getYAxis() + self.setChecked(self.axis.getScale() == self.axis.ARCSINH) + self.axis.sigScaleChanged.connect(self._setCheckedIfArcsinhScale) + + def _setCheckedIfArcsinhScale(self, scale): + self.setChecked(scale == self.axis.ARCSINH) + + def _actionTriggered(self, checked=False): + scale = self.axis.ARCSINH if checked else self.axis.LINEAR + self.axis.setScale(scale) + class GridAction(PlotAction): """QAction controlling grid mode on a :class:`.PlotWidget`. diff --git a/src/silx/gui/plot/backends/BackendMatplotlib.py b/src/silx/gui/plot/backends/BackendMatplotlib.py index 434815bc86..df2dda6ca1 100755 --- a/src/silx/gui/plot/backends/BackendMatplotlib.py +++ b/src/silx/gui/plot/backends/BackendMatplotlib.py @@ -1321,6 +1321,17 @@ def setYAxisLogarithmic(self, flag): self.ax.set_yscale("linear") self.ax.yaxis.set_major_formatter(DefaultTickFormatter()) + def setYAxisArcsinh(self, flag): + if flag: + self.ax2.set_yscale("asinh") + self.ax.set_yscale("asinh") + return + + self.ax2.set_yscale("linear") + self.ax2.yaxis.set_major_formatter(DefaultTickFormatter()) + self.ax.set_yscale("linear") + self.ax.yaxis.set_major_formatter(DefaultTickFormatter()) + def setYAxisInverted(self, flag): if self.ax.yaxis_inverted() != bool(flag): self.ax.invert_yaxis() diff --git a/src/silx/gui/plot/backends/BackendOpenGL.py b/src/silx/gui/plot/backends/BackendOpenGL.py index e21d63ac9c..5746690fde 100755 --- a/src/silx/gui/plot/backends/BackendOpenGL.py +++ b/src/silx/gui/plot/backends/BackendOpenGL.py @@ -1596,6 +1596,9 @@ def setYAxisLogarithmic(self, flag): self._plotFrame.yAxis.isLog = flag self._plotFrame.y2Axis.isLog = flag + def setYAxisArcsinh(self, flag): + ... + def setYAxisInverted(self, flag): if flag != self._plotFrame.isYAxisInverted: self._plotFrame.isYAxisInverted = flag diff --git a/src/silx/gui/plot/items/axis.py b/src/silx/gui/plot/items/axis.py index d96a6a9067..c6a15da2d5 100644 --- a/src/silx/gui/plot/items/axis.py +++ b/src/silx/gui/plot/items/axis.py @@ -63,7 +63,10 @@ class Axis(qt.QObject): LOGARITHMIC = "log" """Constant defining a logarithmic scale""" - _SCALES = {LINEAR, LOGARITHMIC} + ARCSINH = "arcsinh" + """Constant defining an arcsinh scale""" + + _SCALES = {LINEAR, LOGARITHMIC, ARCSINH} sigInvertedChanged = qt.Signal(bool) """Signal emitted when axis orientation has changed""" @@ -242,7 +245,6 @@ def setScale(self, scale): for item in plot.getItems(): item._updated() plot._invalidateDataRange() - if scale == self.LOGARITHMIC: self._internalSetLogarithmic(True) if vmin <= 0: @@ -254,6 +256,8 @@ def setScale(self, scale): self.setLimits(dataRange[0], vmax) else: self.setLimits(*dataRange) + elif scale == self.ARCSINH: + self._internalSetArcsinh(True) elif scale == self.LINEAR: self._internalSetLogarithmic(False) else: @@ -451,6 +455,9 @@ def _internalSetLimits(self, ymin, ymax): def _internalSetLogarithmic(self, flag): self._getBackend().setYAxisLogarithmic(flag) + def _internalSetArcsinh(self, flag): + self._getBackend().setYAxisArcsinh(flag) + def setInverted(self, flag=True): """Set the axis orientation. diff --git a/src/silx/resources/gui/icons/plot-yasinh.svg b/src/silx/resources/gui/icons/plot-yasinh.svg new file mode 100644 index 0000000000..b520d46a66 --- /dev/null +++ b/src/silx/resources/gui/icons/plot-yasinh.svg @@ -0,0 +1,10 @@ + + + + + + + + + asinh + \ No newline at end of file