1 year ago

#290675

test-img

ks905383

Rotating cartopy map by 90 degrees

I'm trying to create a map using cartopy, but have that map be rotated 90 degrees (see image below for a rough sketch of what I'm trying to do*). Here's a rough sketch of what I want to do which was produced using the following code:

import xarray as xr
from cartopy import crs as ccrs
from matplotlib import pyplot as plt

ds = xr.open_dataset('http://iridl.ldeo.columbia.edu/SOURCES/.CAC/climatology+.sst/dods',
                decode_times=False)
ax = plt.subplot(projection=ccrs.PlateCarree())
ds.sel(X=slice(130,150)).mean('T').sst.plot(transform=ccrs.PlateCarree())
ax.coastlines()

Now, thanks to this answer I know that I can achieve this easily without going into cartopy using matplotlib transforms:

import xarray as xr
from matplotlib import pyplot as plt
from matplotlib import transforms

ds = xr.open_dataset('http://iridl.ldeo.columbia.edu/SOURCES/.CAC/climatology+.sst/dods',
                decode_times=False)

ax = plt.subplot()
base = ax.transData
rot = transforms.Affine2D().rotate_deg(270)
plt.pcolormesh(ds.sel(X=slice(130,150)).X,
               ds.Y,
               ds.sel(X=slice(130,150)).mean('T').sst,transform= rot + base)
ax.set_aspect('equal')

which produces: enter image description here (and sure, the longitude labels are off because of the transform, but I'd have deleted the axis labels anyways)

However, I would like to plot coastlines (and country borders, from natural earth), which is something that one can do using cartopy's built-in functions, but which isn't compatible with the Affine2D() transform (and, presumably, matplotlib's built-in transforms in general).

So - basically, is there a way to produce that rotated figure, without losing access to cartopy's coastlines and border plotting methods? I could imagine either

  • some input to ccrs.PlateCarree() that I'm missing?
  • some way to rotate the entire subplot in matplotlib without touching its contents at all?

I appreciate any help!

*(basically, I'm showing SSTs - not with this data, this is just sample data that's easily downloadable - of a meridional slice of the globe, and will be showing other atmospheric variables above that meridional slice in a vertical x latitude subplot above that, with matching latitudes, so I need the map to be horizontal)

Update:

Downloading shapefiles for country borders / coastlines myself (e.g., from NaturalEarth, instead of using cartopy's built-in basic shapefile management system) allows them to be inputted into the figure using the same transform as before.

This still doesn't quite get what I want (full cartopy crs support for the rotated figure) but is a lot closer.

python

matplotlib

matplotlib-basemap

cartopy

0 Answers

Your Answer

Accepted video resources