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
<xarray.Dataset>
Dimensions:  (lat: 64, lon: 128, time: 2)
Coordinates:
  * lat      (lat) float32 -87.8638 -85.09653 -82.31291 ... 85.09653 87.8638
  * lon      (lon) float32 -180.0 -177.1875 -174.375 ... 174.375 177.1875
  * time     (time) int32 1 7
Data variables:
    gw       (lat) float32 0.0017832807 0.004147033 ... 0.004147033 0.0017832807
    U        (time, lat, lon) float32 2.0942385 2.3456185 ... 1.3936923
    V        (time, lat, lon) float32 -4.421005 -4.3354754 ... -0.3070775
Attributes:
    title:          UV300: January and July
    source:         Climate Analysis Section, NCAR
    history:        Dataset uv300.hs from EZPLOT demo dataset
    Conventions:    None
    creation_date:  Mon Mar 29 09:24:57 MST 1999
    references:     \nEZPLOT for Publication Quality Plots\nChristian Guillem...
ds = ds.isel(time=1)
ds
<xarray.Dataset>
Dimensions:  (lat: 64, lon: 128)
Coordinates:
  * lat      (lat) float32 -87.8638 -85.09653 -82.31291 ... 85.09653 87.8638
  * lon      (lon) float32 -180.0 -177.1875 -174.375 ... 174.375 177.1875
    time     int32 7
Data variables:
    gw       (lat) float32 0.0017832807 0.004147033 ... 0.004147033 0.0017832807
    U        (lat, lon) float32 -1.8150927 -1.6226397 ... 1.3709666 1.3936923
    V        (lat, lon) float32 -4.1471963 -4.256537 ... -0.31886855 -0.3070775
Attributes:
    title:          UV300: January and July
    source:         Climate Analysis Section, NCAR
    history:        Dataset uv300.hs from EZPLOT demo dataset
    Conventions:    None
    creation_date:  Mon Mar 29 09:24:57 MST 1999
    references:     \nEZPLOT for Publication Quality Plots\nChristian Guillem...

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
xarray     0.12.1
hvplot     0.4.0
numpy      1.16.4
geoviews   1.6.2
holoviews  1.12.3
matplotlib 3.1.0
cartopy    0.17.0
last updated: 2019-05-28 

CPython 3.6.7
IPython 6.2.1

compiler   : GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)
system     : Darwin
release    : 18.6.0
machine    : x86_64
processor  : i386
CPU cores  : 8
interpreter: 64bit
Git hash   : f8f0e40953ef46b1f9db0c9b2205df45f642aa2a