diff --git a/CHANGES.md b/CHANGES.md index de2fc14cc..f4abbb03c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -40,6 +40,9 @@ v0.8 (unreleased) * Add the ability to change the foreground and background color for viewers. [#988] +* Fixed a bug that caused images to appear over-pixellated on the edges when + zooming in. [#1000] + v0.7.3 (2016-05-04) ------------------- diff --git a/glue/tests/helpers.py b/glue/tests/helpers.py index 2486616d3..94e516bd2 100644 --- a/glue/tests/helpers.py +++ b/glue/tests/helpers.py @@ -34,6 +34,10 @@ def make_skipper(module, label=None, version=None): label='Astropy >= 0.4', version='0.4') +MATPLOTLIB_GE_14_INSTALLED, requires_matplotlib_ge_14 = make_skipper('matplotlib', + label='Matplotlib >= 1.4', + version='1.4') + ASTRODENDRO_INSTALLED, requires_astrodendro = make_skipper('astrodendro') SCIPY_INSTALLED, requires_scipy = make_skipper('scipy', @@ -90,4 +94,4 @@ def make_file(contents, suffix, decompress=False): try: os.unlink(fname) except WindowsError: # on Windows the unlink can fail - pass \ No newline at end of file + pass diff --git a/glue/viewers/image/client.py b/glue/viewers/image/client.py index 39e12cca3..3e71bf4a9 100644 --- a/glue/viewers/image/client.py +++ b/glue/viewers/image/client.py @@ -769,16 +769,28 @@ def check_update(self, *args): For the Matplotlib client, see if the view window has changed enough such that the images should be resampled """ + logging.getLogger(__name__).debug("check update") + + # We need to make sure we reapply the aspect ratio manually here, + # because at this point, if the user has zoomed in to a region with a + # different aspect ratio than the original view, Matplotlib has not yet + # enforced computed the final limits. This is an issue if we have + # requested square pixels. + self.axes.apply_aspect() + vw = _view_window(self._axes) + if vw != self._view_window: logging.getLogger(__name__).debug("updating") self._update_and_redraw() self._view_window = vw def _update_and_redraw(self): + self._update_data_plot() self._update_subset_plots() + self._redraw() @requires_data diff --git a/glue/viewers/image/qt/tests/baseline/test_resample_on_zoom.png b/glue/viewers/image/qt/tests/baseline/test_resample_on_zoom.png new file mode 100644 index 000000000..2466c6311 Binary files /dev/null and b/glue/viewers/image/qt/tests/baseline/test_resample_on_zoom.png differ diff --git a/glue/viewers/image/qt/tests/test_regression.py b/glue/viewers/image/qt/tests/test_regression.py new file mode 100644 index 000000000..e6c4b6408 --- /dev/null +++ b/glue/viewers/image/qt/tests/test_regression.py @@ -0,0 +1,38 @@ +# Miscellaneous regression tests for the image viewer + +import pytest +import numpy as np + +from glue.core import Data +from glue.viewers.image.qt import ImageWidget +from glue.core.tests.util import simple_session +from glue.tests.helpers import requires_matplotlib_ge_14 + + +@requires_matplotlib_ge_14 +@pytest.mark.mpl_image_compare(tolerance=1, savefig_kwargs={'dpi': 50}) +def test_resample_on_zoom(): + + # For images where the aspect ratio of pixels is fixed to be square, when + # the user zooms in, the limits of the axes are actually changed twice by + # matplotlib - a second time when the aspect ratio is enforced. So we need + # to make sure that we update the modest_image when this is the case. + + session = simple_session() + + np.random.seed(12345) + + data = Data(x=np.random.random((2048, 2048)), label='image') + session.data_collection.append(data) + + image = ImageWidget(session=session) + image.add_data(data) + + image.show() + + image.axes.figure.canvas.key_press_event('o') + image.axes.figure.canvas.button_press_event(200, 200, 1) + image.axes.figure.canvas.motion_notify_event(400, 210) + image.axes.figure.canvas.button_release_event(400, 210, 1) + + return image.axes.figure