# Cartopy Examples

https://scitools.org.uk/cartopy/docs/latest/gallery/

In :
import cartopy
cartopy.__version__

'0.18.0'
In :
import matplotlib.pyplot as plt
import numpy as np

import cartopy.crs as ccrs
import cartopy.feature as cfeature

def sample_data(shape=(20, 30)):
"""
Return (x, y, u, v, crs) of some vector data
computed mathematically. The returned crs will be a rotated
pole CRS, meaning that the vectors will be unevenly spaced in
regular PlateCarree space.

"""
crs = ccrs.RotatedPole(pole_longitude=177.5, pole_latitude=37.5)

x = np.linspace(311.9, 391.1, shape)
y = np.linspace(-23.6, 24.8, shape)

x2d, y2d = np.meshgrid(x, y)
u = 10 * (2 * np.cos(2 * np.deg2rad(x2d) + 3 * np.deg2rad(y2d + 30))**2)
v = 20 * np.cos(6 * np.deg2rad(x2d))

return x, y, u, v, crs

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection=ccrs.Orthographic(-10, 45))

ax.add_feature(cfeature.OCEAN, zorder=0)
ax.add_feature(cfeature.LAND, zorder=0, edgecolor='black')

ax.set_global()
ax.gridlines()

x, y, u, v, vector_crs = sample_data()
ax.quiver(x, y, u, v, transform=vector_crs)

plt.show()

/usr/local/lib/python3.8/dist-packages/cartopy/io/__init__.py:260: DownloadWarning: Downloading: https://naciscdn.org/naturalearth/110m/physical/ne_110m_ocean.zip warnings.warn('Downloading: {}'.format(url), DownloadWarning) /usr/local/lib/python3.8/dist-packages/cartopy/io/__init__.py:260: DownloadWarning: Downloading: https://naciscdn.org/naturalearth/110m/physical/ne_110m_land.zip warnings.warn('Downloading: {}'.format(url), DownloadWarning) In :
import matplotlib.pyplot as plt

import cartopy.crs as ccrs
from cartopy.examples.arrows import sample_data

fig = plt.figure(figsize=(10, 5))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([-90, 75, 10, 85], crs=ccrs.PlateCarree())
ax.coastlines()

x, y, u, v, vector_crs = sample_data(shape=(80, 100))
magnitude = (u**2 + v**2)**0.5
ax.streamplot(x,
y,
u,
v,
transform=vector_crs,
linewidth=2,
density=2,
color=magnitude)
plt.show()