From 045ec8f2cf69533fe0b76c392acae2cd86b3a3ff Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Thu, 27 Feb 2020 14:12:39 -0500 Subject: [PATCH] Fix LaTeX error due to labels that become empty in simplify_labels Fixes #8004. --- CHANGES.rst | 3 ++ .../visualization/wcsaxes/tests/test_misc.py | 40 ++++++++++++++++++- astropy/visualization/wcsaxes/ticklabels.py | 2 + 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 080564895571..7c61313232be 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -488,6 +488,9 @@ astropy.visualization maximum when there are less then ``min_npixels`` in the input array. [#9913] +- Fix a bug in simplifying axis labels that affected non-rectangular frames. + [#8004, #9991] + astropy.wcs ^^^^^^^^^^^ diff --git a/astropy/visualization/wcsaxes/tests/test_misc.py b/astropy/visualization/wcsaxes/tests/test_misc.py index 3c10e27f94c1..8b5315bd96a9 100644 --- a/astropy/visualization/wcsaxes/tests/test_misc.py +++ b/astropy/visualization/wcsaxes/tests/test_misc.py @@ -18,7 +18,8 @@ from astropy.tests.image_tests import ignore_matplotlibrc from astropy.visualization.wcsaxes.core import WCSAxes -from astropy.visualization.wcsaxes.frame import RectangularFrame, RectangularFrame1D +from astropy.visualization.wcsaxes.frame import ( + EllipticalFrame, RectangularFrame, RectangularFrame1D) from astropy.visualization.wcsaxes.utils import get_coord_meta from astropy.visualization.wcsaxes.transforms import CurvedTransform @@ -446,3 +447,40 @@ def test_time_wcs(time_spectral_wcs_2d): # with a time axis. plt.subplot(projection=time_spectral_wcs_2d) + + +@pytest.mark.skipif('MATPLOTLIB_LT_21') +@ignore_matplotlibrc +def test_simplify_labels_usetex(tmpdir): + """Regression test for https://github.com/astropy/astropy/issues/8004.""" + plt.rc('text', usetex=True) + + header = { + 'NAXIS': 2, + 'NAXIS1': 360, + 'NAXIS2': 180, + 'CRPIX1': 180.5, + 'CRPIX2': 90.5, + 'CRVAL1': 180.0, + 'CRVAL2': 0.0, + 'CDELT1': -2 * np.sqrt(2) / np.pi, + 'CDELT2': 2 * np.sqrt(2) / np.pi, + 'CTYPE1': 'RA---MOL', + 'CTYPE2': 'DEC--MOL', + 'RADESYS': 'ICRS'} + + wcs = WCS(header) + fig, ax = plt.subplots( + subplot_kw=dict(frame_class=EllipticalFrame, projection=wcs)) + ax.set_xlim(-0.5, header['NAXIS1'] - 0.5) + ax.set_ylim(-0.5, header['NAXIS2'] - 0.5) + ax.coords[0].set_ticklabel(exclude_overlapping=True) + ax.coords[1].set_ticklabel(exclude_overlapping=True) + ax.coords[0].set_ticks(spacing=45 * u.deg) + ax.coords[1].set_ticks(spacing=30 * u.deg) + ax.grid() + + if not matplotlib.checkdep_usetex(True): + pytest.skip('TeX is not available') + + fig.savefig(tmpdir / 'plot.png') diff --git a/astropy/visualization/wcsaxes/ticklabels.py b/astropy/visualization/wcsaxes/ticklabels.py index d515f5abd44c..d910722fd345 100644 --- a/astropy/visualization/wcsaxes/ticklabels.py +++ b/astropy/visualization/wcsaxes/ticklabels.py @@ -93,6 +93,8 @@ def simplify_labels(self): self.text[axis][i] = self.text[axis][i][start:] if starts_dollar: self.text[axis][i] = '$' + self.text[axis][i] + if self.text[axis][i] == '$$': + self.text[axis][i] = '' def set_pad(self, value): self._pad = value