Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/silx/gui/plot/PlotWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +186 to +190
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a new axis scaling changes its control from a boolean to an enum (it should have been so since the beginning).
It would make sense to me to replace yAxisLogarithmicAction with a toolbutton with a drop-down.


self.gridAction = self.group.addAction(
actions.control.GridAction(self, gridMode="both", parent=self)
)
Expand Down
29 changes: 29 additions & 0 deletions src/silx/gui/plot/actions/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
11 changes: 11 additions & 0 deletions src/silx/gui/plot/backends/BackendMatplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Comment on lines +1324 to +1333
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be best to change the backend to have a single place where to set scale for yaxis.
I would replace setYAxisLogarithmic and setYAxisArcsinh by a setScale.

The backend are not marked as private with an _ but they should have and we don't keep the compatibility.


def setYAxisInverted(self, flag):
if self.ax.yaxis_inverted() != bool(flag):
self.ax.invert_yaxis()
Expand Down
3 changes: 3 additions & 0 deletions src/silx/gui/plot/backends/BackendOpenGL.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,9 @@ def setYAxisLogarithmic(self, flag):
self._plotFrame.yAxis.isLog = flag
self._plotFrame.y2Axis.isLog = flag

def setYAxisArcsinh(self, flag):
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
...
raise NotImplementedError("Plot OpenGL backend does not support arcsinh Y axis")


def setYAxisInverted(self, flag):
if flag != self._plotFrame.isYAxisInverted:
self._plotFrame.isYAxisInverted = flag
Expand Down
11 changes: 9 additions & 2 deletions src/silx/gui/plot/items/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Comment on lines +458 to +459
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, _internalSetLogarithmic and _internalSetArcsinh could be replaced by a _internalSetScale


def setInverted(self, flag=True):
"""Set the axis orientation.

Expand Down
10 changes: 10 additions & 0 deletions src/silx/resources/gui/icons/plot-yasinh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.