Skip to content

Commit

Permalink
Merge pull request #1160 from QuLogic/mercator-threshold
Browse files Browse the repository at this point in the history
Use both x/y limits to determine Mercator threshold.
  • Loading branch information
ajdawson authored Oct 30, 2018
2 parents 696e6df + ca2783d commit f19ca5e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/cartopy/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,8 @@ def __init__(self, central_longitude=0.0,
np.array([min_latitude, max_latitude]))
self._xlimits = tuple(limits[..., 0])
self._ylimits = tuple(limits[..., 1])
self._threshold = np.diff(self.x_limits)[0] / 720
self._threshold = min(np.diff(self.x_limits)[0] / 720,
np.diff(self.y_limits)[0] / 360)

def __eq__(self, other):
res = super(Mercator, self).__eq__(other)
Expand Down
22 changes: 21 additions & 1 deletion lib/cartopy/tests/mpl/test_set_extent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# (C) British Crown Copyright 2011 - 2017, Met Office
# (C) British Crown Copyright 2011 - 2018, Met Office
#
# This file is part of cartopy.
#
Expand Down Expand Up @@ -61,6 +61,26 @@ def test_extents():
)


@cleanup
def test_get_extent():
# tests that getting the extents of a map produces something reasonable.
uk = [-12.5, 4, 49, 60]
uk_crs = ccrs.PlateCarree()

ax = plt.axes(projection=ccrs.PlateCarree())
ax.set_extent(uk, crs=uk_crs)
assert_array_almost_equal(ax.get_extent(uk_crs), uk)

ax = plt.axes(projection=ccrs.Mercator())
ax.set_extent(uk, crs=uk_crs)
assert_array_almost_equal(ax.get_extent(uk_crs), uk)

ax = plt.axes(projection=ccrs.Mercator(min_latitude=uk[2],
max_latitude=uk[3]))
ax.set_extent(uk, crs=uk_crs)
assert_array_almost_equal(ax.get_extent(uk_crs), uk, decimal=1)


@cleanup
def test_domain_extents():
# Setting the extent to global or the domain limits.
Expand Down

0 comments on commit f19ca5e

Please sign in to comment.