Skip to content

Commit e17d378

Browse files
committed
Update tests and documentation for change in exclude_overlapping option, and add basic documentation for set_ticklabel
1 parent edcd251 commit e17d378

5 files changed

Lines changed: 38 additions & 27 deletions

File tree

astropy/visualization/wcsaxes/coordinate_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from matplotlib import rcParams
1717

1818
from ... import units as u
19-
from ...exceptions import AstropyDeprecationWarning
19+
from ...utils.exceptions import AstropyDeprecationWarning
2020

2121
from .formatter_locator import AngleFormatterLocator, ScalarFormatterLocator
2222
from .ticks import Ticks

astropy/visualization/wcsaxes/tests/test_images.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,11 @@ def test_cube_slice_image(self):
234234

235235
ax.coords[2].set_axislabel('Velocity m/s')
236236

237-
ax.coords[1].set_ticks(spacing=0.2 * u.deg, width=1,
238-
exclude_overlapping=True)
239-
ax.coords[2].set_ticks(spacing=400 * u.m / u.s, width=1,
240-
exclude_overlapping=True)
237+
ax.coords[1].set_ticks(spacing=0.2 * u.deg, width=1)
238+
ax.coords[2].set_ticks(spacing=400 * u.m / u.s, width=1)
239+
240+
ax.coords[1].set_ticklabel(exclude_overlapping=True)
241+
ax.coords[2].set_ticklabel(exclude_overlapping=True)
241242

242243
ax.coords[1].grid(grid_type='contours', color='red', linestyle='solid')
243244
ax.coords[2].grid(grid_type='contours', color='red', linestyle='solid')
@@ -329,8 +330,10 @@ def test_changed_axis_units(self):
329330
ax.coords[2].set_major_formatter('x.xx')
330331
ax.coords[2].set_format_unit(u.km / u.s)
331332
ax.coords[2].set_axislabel('Velocity km/s')
332-
ax.coords[1].set_ticks(width=1, exclude_overlapping=True)
333-
ax.coords[2].set_ticks(width=1, exclude_overlapping=True)
333+
ax.coords[1].set_ticks(width=1)
334+
ax.coords[2].set_ticks(width=1)
335+
ax.coords[1].set_ticklabel(exclude_overlapping=True)
336+
ax.coords[2].set_ticklabel(exclude_overlapping=True)
334337

335338
return fig
336339

@@ -345,8 +348,8 @@ def test_minor_ticks(self):
345348
slices=(50, 'y', 'x'), aspect='equal')
346349
ax.set_xlim(-0.5, 52.5)
347350
ax.set_ylim(-0.5, 106.5)
348-
ax.coords[2].set_ticks(exclude_overlapping=True)
349-
ax.coords[1].set_ticks(exclude_overlapping=True)
351+
ax.coords[2].set_ticklabel(exclude_overlapping=True)
352+
ax.coords[1].set_ticklabel(exclude_overlapping=True)
350353
ax.coords[2].display_minor_ticks(True)
351354
ax.coords[1].display_minor_ticks(True)
352355
ax.coords[2].set_minor_frequency(3)
@@ -424,8 +427,8 @@ def test_rcparams(self):
424427
ax.grid()
425428
ax.set_xlabel('X label')
426429
ax.set_ylabel('Y label')
427-
ax.coords[0].set_ticks(exclude_overlapping=True)
428-
ax.coords[1].set_ticks(exclude_overlapping=True)
430+
ax.coords[0].set_ticklabel(exclude_overlapping=True)
431+
ax.coords[1].set_ticklabel(exclude_overlapping=True)
429432
return fig
430433

431434
@pytest.mark.remote_data(source='astropy')
@@ -498,8 +501,8 @@ def test_set_coord_type(self):
498501
ax.coords[1].set_coord_type('scalar')
499502
ax.coords[0].set_major_formatter('x.xxx')
500503
ax.coords[1].set_major_formatter('x.xxx')
501-
ax.coords[0].set_ticks(exclude_overlapping=True)
502-
ax.coords[1].set_ticks(exclude_overlapping=True)
504+
ax.coords[0].set_ticklabel(exclude_overlapping=True)
505+
ax.coords[1].set_ticklabel(exclude_overlapping=True)
503506
return fig
504507

505508
@pytest.mark.remote_data(source='astropy')

astropy/visualization/wcsaxes/tests/test_transform_coord_meta.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ def test_coords_overlay(self):
9393
overlay['lon'].grid(color='red', linestyle='solid', alpha=0.3)
9494
overlay['lat'].grid(color='blue', linestyle='solid', alpha=0.3)
9595

96-
overlay['lon'].set_ticklabel(size=7)
97-
overlay['lat'].set_ticklabel(size=7)
96+
overlay['lon'].set_ticklabel(size=7, exclude_overlapping=True)
97+
overlay['lat'].set_ticklabel(size=7, exclude_overlapping=True)
9898

9999
overlay['lon'].set_ticklabel_position('brtl')
100100
overlay['lat'].set_ticklabel_position('brtl')
101101

102-
overlay['lon'].set_ticks(spacing=10. * u.deg, exclude_overlapping=True)
103-
overlay['lat'].set_ticks(spacing=10. * u.deg, exclude_overlapping=True)
102+
overlay['lon'].set_ticks(spacing=10. * u.deg)
103+
overlay['lat'].set_ticks(spacing=10. * u.deg)
104104

105105
ax.set_xlim(-0.5, 1215.5)
106106
ax.set_ylim(-0.5, 1791.5)
@@ -151,14 +151,14 @@ def test_direct_init(self):
151151
ax.coords['lon'].grid(color='red', linestyle='solid', alpha=0.3)
152152
ax.coords['lat'].grid(color='blue', linestyle='solid', alpha=0.3)
153153

154-
ax.coords['lon'].set_ticklabel(size=7)
155-
ax.coords['lat'].set_ticklabel(size=7)
154+
ax.coords['lon'].set_ticklabel(size=7, exclude_overlapping=True)
155+
ax.coords['lat'].set_ticklabel(size=7, exclude_overlapping=True)
156156

157157
ax.coords['lon'].set_ticklabel_position('brtl')
158158
ax.coords['lat'].set_ticklabel_position('brtl')
159159

160-
ax.coords['lon'].set_ticks(spacing=10. * u.deg, exclude_overlapping=True)
161-
ax.coords['lat'].set_ticks(spacing=10. * u.deg, exclude_overlapping=True)
160+
ax.coords['lon'].set_ticks(spacing=10. * u.deg)
161+
ax.coords['lat'].set_ticks(spacing=10. * u.deg)
162162

163163
ax.set_xlim(-400., 500.)
164164
ax.set_ylim(-300., 400.)

docs/visualization/wcsaxes/slicing_datacubes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ We then add the axes to the image and plot it using the method
7575
:include-source:
7676
:align: center
7777

78-
ax.coords[2].set_ticks(exclude_overlapping=True)
78+
ax.coords[2].set_ticklabel(exclude_overlapping=True)
7979
ax.imshow(image_data[:, :, 50].transpose())
8080

8181
Here, ``image_data`` is an :class:`~numpy.ndarray` object. In Numpy, the order

docs/visualization/wcsaxes/ticks_labels_grid.rst

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,15 @@ In the case of angular axes, specifying the spacing as an Astropy
204204
:class:`~astropy.units.quantity.Quantity` avoids roundoff errors. The
205205
:meth:`~astropy.visualization.wcsaxes.coordinate_helpers.CoordinateHelper.set_ticks` method can also
206206
be used to set the appearance (color and size) of the ticks, using the
207-
``color=`` and ``size=`` options. There is also the option
208-
``exclude_overlapping=True`` to prevent overlapping tick labels from being
209-
displayed.
207+
``color=`` and ``size=`` options.
208+
209+
The :meth:`~astropy.visualization.wcsaxes.coordinate_helpers.CoordinateHelper.set_ticklabel` method can be used
210+
to change settings for the tick labels, such as color, font, size, and so on::
211+
212+
lon.set_ticklabel(color='red', size=12)
213+
214+
In addition, this method has an option ``exclude_overlapping=True`` to prevent
215+
overlapping tick labels from being displayed.
210216

211217
We can apply this to the previous example:
212218

@@ -216,8 +222,10 @@ We can apply this to the previous example:
216222
:align: center
217223

218224
from astropy import units as u
219-
lon.set_ticks(spacing=10 * u.arcmin, color='white', exclude_overlapping=True)
220-
lat.set_ticks(spacing=10 * u.arcmin, color='white', exclude_overlapping=True)
225+
lon.set_ticks(spacing=10 * u.arcmin, color='white')
226+
lat.set_ticks(spacing=10 * u.arcmin, color='white')
227+
lon.set_ticklabel(exclude_overlapping=True)
228+
lat.set_ticklabel(exclude_overlapping=True)
221229

222230
Minor ticks
223231
***********

0 commit comments

Comments
 (0)