diff --git a/lib/iris/plot.py b/lib/iris/plot.py index 733f85f630..b8e36e0b5a 100644 --- a/lib/iris/plot.py +++ b/lib/iris/plot.py @@ -365,8 +365,6 @@ def _map_common(draw_method_name, arg_func, mode, cube, data, *args, **kwargs): x = numpy.append(x, x[:, 0:1] + 360, axis=1) data = numpy.ma.concatenate([data, data[:, 0:1]], axis=1) - - # Get the native crs and map (might be the same cartopy definiton) cs = cube.coord_system('CoordSystem') cartopy_crs = cs.as_cartopy_crs() # E.g. Geodetic @@ -405,7 +403,7 @@ def _map_common(draw_method_name, arg_func, mode, cube, data, *args, **kwargs): # Set the "from transform" keyword. assert 'transform' not in kwargs, 'Transform keyword is not allowed.' - kwargs['transform'] = cartopy_crs._as_mpl_transform(ax) + kwargs['transform'] = cartopy_crs if arg_func is not None: new_args, kwargs = arg_func(x, y, data, *args, **kwargs) @@ -554,39 +552,37 @@ def map_setup(projection=None, xlim=None, ylim=None, cube=None, mode=None): if projection is None: projection = cartopy.crs.PlateCarree() + lim_crs = projection + # Which extents? if (xlim is None or ylim is None) and cube is not None: mode = mode or iris.coords.BOUND_MODE extents = iris.analysis.cartography.xy_range(cube, mode, projection) xlim = extents[0] ylim = extents[1] + lim_crs = cs.as_cartopy_crs() if cs else None # TODO: Refactor with _map_common() # Replace the current axis with a cartopy one fig = plt.gcf() ax = plt.gca() if isinstance(ax, matplotlib.axes.SubplotBase): - # xlim = None has special meaning, and must be avoided. - if xlim is None: - new_ax = fig.add_subplot(ax.get_subplotspec(), projection=projection, - title=ax.get_title(), xlabel=ax.get_xlabel(), - ylabel=ax.get_ylabel()) - else: - new_ax = fig.add_subplot(ax.get_subplotspec(), projection=projection, - xlim=xlim, ylim=ylim, + new_ax = fig.add_subplot(ax.get_subplotspec(), projection=projection, title=ax.get_title(), xlabel=ax.get_xlabel(), ylabel=ax.get_ylabel()) - else: - if xlim is None: - new_ax = fig.add_axes(projection=projection, #xlim=xlim, ylim=ylim, - title=ax.get_title(), xlabel=ax.get_xlabel(), - ylabel=ax.get_ylabel()) - else: - new_ax = fig.add_axes(projection=projection, xlim=xlim, ylim=ylim, - title=ax.get_title(), xlabel=ax.get_xlabel(), - ylabel=ax.get_ylabel()) + new_ax = fig.add_axes(projection=projection, + title=ax.get_title(), xlabel=ax.get_xlabel(), + ylabel=ax.get_ylabel()) + + if xlim is not None != ylim is not None: + warnings.warn('Both xlim and ylim must currently be set.') + + if xlim is not None: + new_ax.set_extent(tuple(xlim) + tuple(ylim), lim_crs) + fig.delaxes(ax) + return new_ax def _fill_orography(cube, coords, mode, vert_plot, horiz_plot, style_args): diff --git a/lib/iris/tests/results/visual_tests/test_cmap_norm.TestCmapNorm.test_cmap_override.1.png b/lib/iris/tests/results/visual_tests/test_cmap_norm.TestCmapNorm.test_cmap_override.1.png index e736fe795f..3395117ce0 100644 Binary files a/lib/iris/tests/results/visual_tests/test_cmap_norm.TestCmapNorm.test_cmap_override.1.png and b/lib/iris/tests/results/visual_tests/test_cmap_norm.TestCmapNorm.test_cmap_override.1.png differ diff --git a/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_keywords.1.png b/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_keywords.1.png index 85fa292fce..e983b86a2d 100644 Binary files a/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_keywords.1.png and b/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_keywords.1.png differ diff --git a/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.1.png b/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.1.png index 77ffc51f13..cd3d849373 100644 Binary files a/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.1.png and b/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.1.png differ diff --git a/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.2.png b/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.2.png index 50e3adc37c..f20339f772 100644 Binary files a/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.2.png and b/lib/iris/tests/results/visual_tests/test_mapping.TestLowLevel.test_params.2.png differ diff --git a/lib/iris/tests/results/visual_tests/test_mapping.TestMappingSubRegion.test_simple.0.png b/lib/iris/tests/results/visual_tests/test_mapping.TestMappingSubRegion.test_simple.0.png index fed5179af0..4d146a943d 100644 Binary files a/lib/iris/tests/results/visual_tests/test_mapping.TestMappingSubRegion.test_simple.0.png and b/lib/iris/tests/results/visual_tests/test_mapping.TestMappingSubRegion.test_simple.0.png differ diff --git a/lib/iris/tests/test_mapping.py b/lib/iris/tests/test_mapping.py index 32444162a7..f2f67b9706 100644 --- a/lib/iris/tests/test_mapping.py +++ b/lib/iris/tests/test_mapping.py @@ -92,45 +92,36 @@ class TestMappingSubRegion(tests.IrisTest): def setUp(self): cube_path = tests.get_data_path(('PP', 'aPProt1', 'rotatedMHtimecube.pp')) cube = iris.load_strict(cube_path)[0] - - # Until there is better mapping support for rotated-pole, pretend this isn't rotated. - # ie. Move the pole from (37.5, 177.5) to (90, 0) and bodge the coordinates. -# _pretend_unrotated(cube) - - self.cube = cube + # make the data slighly smaller to speed things up... + self.cube = cube[::10, ::10] def test_simple(self): # First sub-plot plt.subplot(221) plt.title('Default') - iplt.contourf(self.cube) plt.gca().coastlines() # Second sub-plot plt.subplot(222) plt.title('Molleweide') - iplt.map_setup(projection=ccrs.Mollweide(central_longitude=120)) iplt.contourf(self.cube) - plt.gca().set_global() # TODO: REMOVE THIS ADDITION, PENDING FIX plt.gca().coastlines() # Third sub-plot plt.subplot(223) plt.title('Native') - - iplt.map_setup(cube=self.cube) - iplt.contourf(self.cube) - plt.gca().coastlines() + ax = iplt.map_setup(cube=self.cube) + iplt.contour(self.cube) + ax.coastlines() # Fourth sub-plot plt.subplot(224) - plt.title('Three/six level') - - contour1 = iplt.contourf(self.cube, 3) - contour2 = iplt.contour(self.cube, 6) - plt.gca().coastlines() + plt.title('PlateCarree') + ax = plt.subplot(2, 2, 4, projection=ccrs.PlateCarree()) + iplt.contourf(self.cube) + ax.coastlines() self.check_graphic()