Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Matplotlib Axes checkbox #2128

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9b7284a
qt viewer shows/hides axes with the show_axes state property
jsub1 Mar 5, 2020
bbc3d90
Add checkbox to show/hide axis for matplotlib viewers
jsub1 Mar 5, 2020
5bd71fe
Export the show_axes option when creating a python script
jsub1 Mar 5, 2020
411c7a8
Add tests for hiding the axis both in the viewer and in the python ex…
jsub1 Mar 5, 2020
e1b71f8
Formatting & typo
jsub1 Mar 5, 2020
fc28d8f
Make sure the show/hide axes can be applied to all plots via button
jsub1 Mar 5, 2020
17f2012
Added quick test for update_settings_from method
jsub1 May 6, 2020
51e05a8
Prevent recalculating WCS on image cubes when slicing through with hi…
jsub1 May 18, 2020
414d3e4
Remove margin when hiding axes
jsub1 May 18, 2020
e234eb6
Remove margin when exporting to script
jsub1 May 19, 2020
cc8c4af
Fix typo in test that prevented it from actually testing hiding the a…
jsub1 May 26, 2020
2c6ac46
Added test see when we recalculate the wcs axes for image viewer
jsub1 Jun 9, 2020
8cb1ddf
Change the python export hide axes test for the image. The equal aspe…
jsub1 Jun 11, 2020
ba2eafd
Formatting fixes
jsub1 Jun 11, 2020
16f54f5
Rebase conflict fix
jsub1 Jun 12, 2020
44813bd
Rebase conflict fix 2
jsub1 Jun 12, 2020
92f359a
Fix state sync for legned and reset import to use echo directly
jsub1 Jun 12, 2020
92f98e6
Fixed a bug that caused an exception when exporting an image with WCS…
jsub1 Jun 15, 2020
4c1f6f3
whitespace
jsub1 Jun 15, 2020
62785cd
See if CI behaves better if we explicitly set the limits for the imag…
jsub1 Jul 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions glue/viewers/image/qt/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from collections import Counter

import pytest
from unittest.mock import MagicMock

from astropy.wcs import WCS

Expand Down Expand Up @@ -740,6 +741,41 @@ def test_legend(self):

assert to_hex(handles[1].get_facecolor()) == viewer_state.layers[1].color

def test_recalculate_wcs(self):

# Test to make sure we skip recalculating WCS when appropriate

mock = MagicMock(wraps=self.viewer.axes.reset_wcs)
self.viewer.axes.reset_wcs = mock

coords = self.hypercube_wcs.coords
coords.wcs.crpix = [1.2, 2, 2.25, 1.9]
coords.wcs.cdelt = np.array([-6.7, 6.7, 5.1, -4.6])
coords.wcs.crval = [0, -90, 10, 40]
coords.wcs.ctype = ["RA---SFL", "DEC--SFL", "VOPT", "ZOPT"]
coords.wcs.specsys = "LSRK"
self.viewer.add_data(self.hypercube_wcs)
self.viewer.state.x_att = self.hypercube_wcs.pixel_component_ids[0]
self.viewer.state.y_att = self.hypercube_wcs.pixel_component_ids[3]
self.viewer.state.slices = [0, 0, 0, 0]

mock.reset_mock()
self.viewer.state.slices = [0, 2, 3, 0]
mock.assert_called()

mock.reset_mock()
self.viewer.state.show_axes = False
self.viewer.state.slices = [0, 1, 0, 0]
mock.assert_not_called()

mock.reset_mock()
self.viewer.state.x_att = self.hypercube_wcs.pixel_component_ids[1]
mock.assert_called()

mock.reset_mock()
self.viewer.state.slices = [1, 1, 0, 0]
mock.assert_not_called()


class TestSessions(object):

Expand Down
15 changes: 15 additions & 0 deletions glue/viewers/image/qt/tests/test_python_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from glue.viewers.image.qt import ImageViewer
from glue.viewers.matplotlib.qt.tests.test_python_export import BaseTestExportPython

from astropy.wcs import WCS


class TestExportPython(BaseTestExportPython):

Expand Down Expand Up @@ -85,3 +87,16 @@ def test_subset_transposed(self, tmpdir):
self.viewer.state.y_att = self.data.pixel_component_ids[1]
self.data_collection.new_subset_group('mysubset', self.data.id['cube'] > 0.5)
self.assert_same(tmpdir)

def test_hide_axes(self, tmpdir):
self.viewer.state.aspect = 'auto'
self.viewer.state.x_min = -5
self.viewer.state.y_min = -3
self.viewer.state.x_max = 30
self.viewer.state.y_max = 55
super().test_hide_axes(tmpdir)

def test_wcs_image(self, tmpdir):
coords = WCS(naxis=3)
wcs_data = Data(self.data.data)
self.assert_same(tmpdir)
11 changes: 9 additions & 2 deletions glue/viewers/image/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def update_y_ticklabel(self, *event):
self.axes.coords[axis].set_ticklabel(size=self.state.y_ticklabel_size)
self.redraw()

def update_axes_visibility(self, *event):
if self.state.show_axes:
self._set_wcs()
else:
self._changing_slice_requires_wcs_update = False
super(MatplotlibImageMixin, self).update_axes_visibility(event)

def _update_axes(self, *args):

if self.state.x_att_world is not None:
Expand Down Expand Up @@ -132,7 +139,7 @@ def _set_wcs(self, event=None, relim=True):
y_dep.remove(ix)
if iy in y_dep:
y_dep.remove(iy)
self._changing_slice_requires_wcs_update = bool(x_dep or y_dep)
self._changing_slice_requires_wcs_update = bool(x_dep or y_dep) and self.state.show_axes

self._wcs_set = True

Expand Down Expand Up @@ -219,7 +226,7 @@ def _script_header(self):
ref_coords = self.state.reference_data.coords

if hasattr(ref_coords, 'wcs'):
script += "ax.reset_wcs(slices={0}, wcs=ref_data.coords.wcs)\n".format(self.state.wcsaxes_slice)
script += "ax.reset_wcs(slices={0}, wcs=ref_data.coords)\n".format(self.state.wcsaxes_slice)
elif hasattr(ref_coords, 'wcsaxes_dict'):
raise NotImplementedError()
else:
Expand Down
4 changes: 3 additions & 1 deletion glue/viewers/matplotlib/mpl_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

__all__ = ['update_appearance_from_settings', 'init_mpl']

DEFAULT_MARGIN = [1, 0.25, 0.50, 0.25]


def set_background_color(axes, color):
axes.figure.set_facecolor(color)
Expand Down Expand Up @@ -59,7 +61,7 @@ def init_mpl(figure=None, axes=None, wcs=False, axes_factory=None):
else:
_axes = axes_factory(_figure)

freeze_margins(_axes, margins=[1, 0.25, 0.50, 0.25])
freeze_margins(_axes, margins=DEFAULT_MARGIN)

update_appearance_from_settings(_axes)

Expand Down
Loading