Skip to content

Commit

Permalink
Merge pull request #704 from ajdawson/set-extent-exception
Browse files Browse the repository at this point in the history
Improve error message from setting an invalid extent.
  • Loading branch information
pelson committed Dec 10, 2015
2 parents 1ac2789 + 4513d3a commit d6de800
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/cartopy/mpl/geoaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,18 @@ def set_extent(self, extents, crs=None):

if projected is None:
projected = self.projection.project_geometry(domain_in_crs, crs)
x1, y1, x2, y2 = projected.bounds
try:
# This might fail with an unhelpful error message ('need more
# than 0 values to unpack') if the specified extents fall outside
# the projection extents, so try and give a better error message.
x1, y1, x2, y2 = projected.bounds
except ValueError:
msg = ('Failed to determine the required bounds in projection '
'coordinates. Check that the values provided are within '
'the valid range (x_limits=[{xlim[0]}, {xlim[1]}], '
'y_limits=[{ylim[0]}, {ylim[1]}]).')
raise ValueError(msg.format(xlim=self.projection.x_limits,
ylim=self.projection.y_limits))
self.set_xlim([x1, x2])
self.set_ylim([y1, y2])

Expand Down

0 comments on commit d6de800

Please sign in to comment.