Andrew Dawson has made some excellent contributions to cartopy's vector quantity visualisations recently. As these features are un-released as yet, this notebook is working with cartopy master:

In [1]:
import cartopy

cartopy.__version__
Out[1]:
'0.10.x'
In [2]:
import cartopy.crs as ccrs
import numpy as np
import matplotlib.pyplot as plt

Lets fake up some data on a rotated pole coordinate system:

In [3]:
x = np.linspace(312, 392, 20)
y = np.linspace(-23, 25, 25)

x2d, y2d = np.meshgrid(np.deg2rad(x), np.deg2rad(y))
u = (np.cos(2 * x2d + 1) * np.cos(4 * y2d + 1)) * 6
v = -8 * (np.cos(2. * y2d) * np.sin(3 * x2d))

data_cs = ccrs.RotatedPole(pole_longitude=177.5, pole_latitude=37.5)

mag = (u**2 + v**2)**.5

Lets do a basic visualisation of the data:

In [4]:
plt.figure(figsize=(12, 12))
ax = plt.axes(projection=data_cs)
ax.coastlines('50m')

plt.margins(0.3)
ax.quiver(x, y, u, v, mag, transform=data_cs)
#ax.stock_img()
plt.show()

We can also plot these vectors in any other coordinate system:

In [5]:
plt.figure(figsize=(12, 12))
ax = plt.axes(projection=ccrs.Orthographic(central_latitude=15))
ax.coastlines('50m')

plt.margins(0.3)
ax.quiver(x, y, u, v, mag, transform=data_cs)
ax.stock_img()
plt.show()

Sometimes we want the vectors to be resampled to have a regular spacing in the target projection:

In [6]:
plot_extent = [-60, 40, 30, 70]
plt.figure(figsize=(12, 12))

ax1 = plt.subplot(211, projection=ccrs.PlateCarree())
ax1.set_extent(plot_extent, crs=ccrs.PlateCarree())
ax1.coastlines('50m')
ax1.stock_img()
plt.title('No resampling')
ax1.quiver(x, y, u, v, mag, transform=data_cs)

ax2 = plt.subplot(212, projection=ccrs.PlateCarree())
ax2.set_extent(plot_extent, crs=ccrs.PlateCarree())
ax2.coastlines('50m')
ax2.stock_img()
plt.title('With resampling')
ax2.quiver(x, y, u, v, mag, transform=data_cs, regrid_shape=20)

plt.show()