Skip to content

Commit 49640b9

Browse files
committed
New Z-axis logarithmic scale feature
1 parent 6296668 commit 49640b9

File tree

11 files changed

+700
-407
lines changed

11 files changed

+700
-407
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ In this release, test coverage is 79%.
66

77
💥 New features / Enhancements:
88

9+
* New Z-axis logarithmic scale feature:
10+
* Added new tool `ZAxisLogTool` to toggle the Z-axis logarithmic scale
11+
* The tool is registered by default in the plot widget, like the `ColormapTool`
12+
* When enabled, the active image item is displayed after applying a base-10
13+
logarithm to its pixel values
914
* Curve statistics tool `CurveStatsTool` is now customizable:
1015
* When adding the tool: `plot_widget.manager.add_tool(CurveStatsTool, labelfuncs=(...))`
1116
* Or after: `plot_widget.manager.get_tool(CurveStatsTool).set_labelfuncs(...)`

doc/features/tools/reference.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ Image tools
108108
:members:
109109
.. autoclass:: plotpy.tools.ReverseYAxisTool
110110
:members:
111+
.. autoclass:: plotpy.tools.ZAxisLogTool
112+
:members:
111113
.. autoclass:: plotpy.tools.AspectRatioTool
112114
:members:
113115
.. autoclass:: plotpy.tools.ContrastPanelTool

plotpy/data/icons/zlog.svg

Lines changed: 144 additions & 0 deletions
Loading

plotpy/items/image/image_items.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
)
2929
from plotpy.items.image.base import RawImageItem
3030
from plotpy.items.image.filter import XYImageFilterItem, to_bins
31+
from plotpy.mathutils.arrayfuncs import get_nan_range
3132
from plotpy.styles.image import ImageParam, RGBImageParam, XYImageParam
3233

3334
if TYPE_CHECKING:
@@ -83,6 +84,9 @@ def __init__(
8384
self.xmax = None
8485
self.ymin = None
8586
self.ymax = None
87+
self._log_data = None
88+
self._lin_lut_range = None
89+
self._is_zaxis_log = False
8690
super().__init__(data=data, param=param)
8791

8892
# ---- BaseImageItem API ---------------------------------------------------
@@ -224,6 +228,24 @@ def update_bounds(self) -> None:
224228
(xmin, xmax), (ymin, ymax) = self.get_xdata(), self.get_ydata()
225229
self.bounds = QC.QRectF(QC.QPointF(xmin, ymin), QC.QPointF(xmax, ymax))
226230

231+
def get_zaxis_log_state(self):
232+
"""Reimplement image.ImageItem method"""
233+
return self._is_zaxis_log
234+
235+
def set_zaxis_log_state(self, state):
236+
"""Reimplement image.ImageItem method"""
237+
self._is_zaxis_log = state
238+
plot = self.plot()
239+
if state:
240+
self._lin_lut_range = self.get_lut_range()
241+
if self._log_data is None:
242+
self._log_data = np.array(np.log10(self.data.clip(1)), dtype=np.float64)
243+
self.set_lut_range(get_nan_range(self._log_data))
244+
else:
245+
self._log_data = None
246+
self.set_lut_range(self._lin_lut_range)
247+
plot.update_colormap_axis(self)
248+
227249
# ---- BaseImageItem API ---------------------------------------------------
228250
def get_pixel_coordinates(self, xplot: float, yplot: float) -> tuple[float, float]:
229251
"""Get pixel coordinates from plot coordinates
@@ -356,9 +378,18 @@ def draw_image(
356378
return
357379
src2 = self._rescale_src_rect(src_rect)
358380
dst_rect = tuple([int(i) for i in dst_rect])
381+
382+
# Not the most efficient way to do it, but it works...
383+
# --------------------------------------------------------------------------
384+
if self.get_zaxis_log_state():
385+
data = self._log_data
386+
else:
387+
data = self.data
388+
# --------------------------------------------------------------------------
389+
359390
try:
360391
dest = _scale_rect(
361-
self.data, src2, self._offscreen, dst_rect, self.lut, self.interpolate
392+
data, src2, self._offscreen, dst_rect, self.lut, self.interpolate
362393
)
363394
except ValueError:
364395
# This exception is raised when zooming unreasonably inside a pixel
75 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)