Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
Fix grid and cursor coordinates and added reference image
Browse files Browse the repository at this point in the history
  • Loading branch information
astrofrog committed Jul 20, 2015
1 parent 7fe8332 commit a7d7fca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions wcsaxes/coordinate_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,25 @@ def format_coord(self, value):
Given the value of a coordinate, will format it according to the
format of the formatter_locator.
"""

if not hasattr(self, "_fl_spacing"):
return "" # _update_ticks has not been called yet

fl = self._formatter_locator
if isinstance(fl, AngleFormatterLocator):

# Convert to degrees if needed
if self._coord_unit_scale is not None:
value *= self._coord_unit_scale

if self.coord_type == 'longitude':
value = wrap_angle_at(value, self.coord_wrap)
value = value * u.degree
value = value.to(fl._unit).value

spacing = self._fl_spacing
string = fl.formatter(values=[value] * fl._unit, spacing=spacing)

return string[0]

def set_separator(self, separator):
Expand Down Expand Up @@ -645,6 +654,11 @@ def _update_grid_lines(self):
# single go rather than doing this in the gridline to path conversion
# to fully benefit from vectorized coordinate transformations.

# Currently xy_world is in deg, but transform function needs it in
# native units
if self._coord_unit_scale is not None:
xy_world /= self._coord_unit_scale

# Transform line to pixel coordinates
pixel = self.transform.inverted().transform(xy_world)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion wcsaxes/tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def test_axislabels_regression(self):

@pytest.mark.mpl_image_compare(savefig_kwargs={'bbox_inches': 'tight'},
tolerance=1.5)
def test_noncelestial_angular(self):
def test_noncelestial_angular(self, tmpdir):
# Regression test for a bug that meant that when passing a WCS that had
# angular axes and using set_coord_type to set the coordinates to
# longitude/latitude, but where the WCS wasn't recognized as celestial,
Expand All @@ -387,4 +387,12 @@ def test_noncelestial_angular(self):
ax.coords[0].set_major_formatter('s.s')
ax.coords[1].set_major_formatter('s.s')

ax.grid(color='white', ls='solid')

# Force drawing (needed for format_coord)
fig.savefig(tmpdir.join('nothing').strpath)

# TODO: the formatted string should show units
assert ax.format_coord(512, 512) == "513.0 513.0 (world)"

return fig

0 comments on commit a7d7fca

Please sign in to comment.