Skip to content

Commit

Permalink
Merge pull request #2513 from pllim/fix-yminmax-same
Browse files Browse the repository at this point in the history
Correct y limits in ProfileViewerState when min same as max
  • Loading branch information
astrofrog authored Sep 24, 2024
2 parents 7481caf + acffd4d commit 1c51c7f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions glue/viewers/profile/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ def _reset_y_limits(self, *event):
if y_max > y_min:
self.y_min = y_min
self.y_max = y_max
elif np.allclose(y_min, y_max):
if y_min == 0.0:
dy = np.finfo(y_min).resolution**2
else:
dy = abs(0.1 * y_min)
self.y_min = y_min - dy
self.y_max = y_max + dy
else:
self.y_min = 0
self.y_max = 1
Expand Down
20 changes: 20 additions & 0 deletions glue/viewers/profile/tests/test_state.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from glue.core.data_collection import DataCollection
import numpy as np
import pytest

from numpy.testing import assert_allclose

Expand Down Expand Up @@ -161,3 +162,22 @@ def test_visible(self):
x, y = self.layer_state.profile
assert_allclose(x, [0, 2, 4])
assert_allclose(y, [3.5, 11.5, 19.5])


@pytest.mark.parametrize(('value', 'limits'),
[(0, (-1e-30, 1e-30)),
(1, (0.9, 1.1)),
(-0.1, (-0.11, -0.09))])
def test_limits_profile_y_constant(value, limits):
data = Data(label='d1')
data.coords = SimpleCoordinates()
data['x'] = np.ones(24).reshape((3, 4, 2)).astype(float) * value

data_collection = DataCollection([data])

viewer_state = ProfileViewerState()
layer_state = ProfileLayerState(viewer_state=viewer_state, layer=data)
viewer_state.layers.append(layer_state)
viewer_state.function = 'mean'

assert_allclose((viewer_state.y_min, viewer_state.y_max), limits)

0 comments on commit 1c51c7f

Please sign in to comment.