Cartopy Projections
Cartopy supports several map projections. If you have data that’s on a particular map projection, you can easily project it onto a different map projection.
The purpose of this notebook is to generate a plot using every map projection in Cartopy.
A full list of supported projections can be found here.
%matplotlib inline
import warnings
warnings.simplefilter("ignore") # Silence warnings
import hvplot.xarray
import xarray as xr
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import geoviews as gv
import holoviews as hv
import numpy as np
#hv.extension('bokeh')
Read data
ds = xr.open_dataset("../data/cdf/uv300.nc").load()
ds
ds = ds.isel(time=1)
ds
Define plotting function with some default resources common to all map projections.
def plot(variable='U', projection=ccrs.PlateCarree(), width=600, height=540, levels=10,
cmap='Spectral', global_extent=True, **kwargs):
"""Plot filled countour plots for different cartopy projections while using hvplot/holoviews/geoviews"""
long_name = ds[variable].long_name
units = ds[variable].units
spacing = 80 * " "
title = f'{long_name} {spacing} {units}'
p = ds.hvplot(x='lon', y='lat', z=variable, projection=projection,
width=width, height=height, cmap=cmap, dynamic=False,
kind='contourf', levels=levels, title=title,
legend='bottom', global_extent=global_extent,
ylabel=f'{ds.lat.long_name}[{ds.lat.units}]',
xlabel=f'{ds.lon.long_name}[{ds.lon.units}]',
**kwargs
) * gv.feature.coastline
return p
PlateCarree
plot(projection=ccrs.PlateCarree())
plot(projection=ccrs.PlateCarree(), levels=10)
AlbersEqualArea
plot(projection=ccrs.AlbersEqualArea())
AzimuthalEquidistant
plot(projection=ccrs.AzimuthalEquidistant())
EquidistantConic
plot(projection=ccrs.EquidistantConic())
LambertConformal
plot(projection=ccrs.LambertConformal(), levels=10)
LambertCylindrical
plot(projection=ccrs.LambertCylindrical(central_longitude=-100))
Mercator
plot(projection=ccrs.Mercator())
Miller
plot(projection=ccrs.Miller())
Orthographic
plot(projection=ccrs.Orthographic(0, 90))
plot(projection=ccrs.Orthographic(180, -90))
Robinson
plot(projection=ccrs.Robinson())
SouthPolarStereo
plot(projection=ccrs.SouthPolarStereo())
NorthPolarStereo
plot(projection=ccrs.NorthPolarStereo())
Stereographic
plot(projection=ccrs.Stereographic())
plot(projection=ccrs.Geostationary(central_longitude=-90))
%load_ext watermark
%watermark --iversion -g -m -v -u -d