diff --git a/glue/viewers/profile/state.py b/glue/viewers/profile/state.py index bd096693d..cafb59821 100644 --- a/glue/viewers/profile/state.py +++ b/glue/viewers/profile/state.py @@ -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 diff --git a/glue/viewers/profile/tests/test_state.py b/glue/viewers/profile/tests/test_state.py index c574558db..bd89a25d1 100644 --- a/glue/viewers/profile/tests/test_state.py +++ b/glue/viewers/profile/tests/test_state.py @@ -1,5 +1,6 @@ from glue.core.data_collection import DataCollection import numpy as np +import pytest from numpy.testing import assert_allclose @@ -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)