Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions lib/iris/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 9 additions & 18 deletions lib/iris/tests/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down