|
28 | 28 | ) |
29 | 29 | from plotpy.items.image.base import RawImageItem |
30 | 30 | from plotpy.items.image.filter import XYImageFilterItem, to_bins |
| 31 | +from plotpy.mathutils.arrayfuncs import get_nan_range |
31 | 32 | from plotpy.styles.image import ImageParam, RGBImageParam, XYImageParam |
32 | 33 |
|
33 | 34 | if TYPE_CHECKING: |
@@ -83,6 +84,9 @@ def __init__( |
83 | 84 | self.xmax = None |
84 | 85 | self.ymin = None |
85 | 86 | self.ymax = None |
| 87 | + self._log_data = None |
| 88 | + self._lin_lut_range = None |
| 89 | + self._is_zaxis_log = False |
86 | 90 | super().__init__(data=data, param=param) |
87 | 91 |
|
88 | 92 | # ---- BaseImageItem API --------------------------------------------------- |
@@ -224,6 +228,24 @@ def update_bounds(self) -> None: |
224 | 228 | (xmin, xmax), (ymin, ymax) = self.get_xdata(), self.get_ydata() |
225 | 229 | self.bounds = QC.QRectF(QC.QPointF(xmin, ymin), QC.QPointF(xmax, ymax)) |
226 | 230 |
|
| 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 | + |
227 | 249 | # ---- BaseImageItem API --------------------------------------------------- |
228 | 250 | def get_pixel_coordinates(self, xplot: float, yplot: float) -> tuple[float, float]: |
229 | 251 | """Get pixel coordinates from plot coordinates |
@@ -356,9 +378,18 @@ def draw_image( |
356 | 378 | return |
357 | 379 | src2 = self._rescale_src_rect(src_rect) |
358 | 380 | 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 | + |
359 | 390 | try: |
360 | 391 | 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 |
362 | 393 | ) |
363 | 394 | except ValueError: |
364 | 395 | # This exception is raised when zooming unreasonably inside a pixel |
|
0 commit comments