Orthographic Vectorfield#
Download this notebook from GitHub (right-click to download).
import numpy as np
import geoviews as gv
import geoviews.feature as gf
import cartopy.crs as ccrs
gv.extension('matplotlib')
gv.output(fig='svg', size=200)
Define data#
def sample_data(shape=(20, 30)):
"""
Returns ``(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[1])
y = np.linspace(-23.6, 24.8, shape[0])
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
xs, ys, U, V, crs = sample_data()
mag = np.sqrt(U**2 + V**2)
angle = np.pi / 2 - np.arctan2(-V, -U)
vectorfield = gv.VectorField((xs, ys, angle, mag), crs=crs)
Plot#
gf.ocean * gf.coastline * gf.land * vectorfield.opts(
magnitude='Magnitude', show_grid=True, projection=ccrs.Orthographic(-10, 45), global_extent=True)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.
Download this notebook from GitHub (right-click to download).