# Projections ¶

In [1]:
import iris
import numpy as np
import holoviews as hv
import geoviews as gv
import geoviews.feature as gf
from cartopy import crs
hv.notebook_extension()


The  geoviews  package provides a library of Element types which make it very easy to plot data on various geographic projections. Depending on the type of data, the plotting code will automatically infer the correct  transform  and a default output  projection  .

In [2]:
%%output size=400
features = hv.Overlay([gf.land, gf.ocean, gf.rivers, gf.lakes, gf.borders, gf.coastline])
features

Out[2]:

The Bokeh backend currently only supports one output projection (web Mercator), but with the matplotlib backend you can choose between any of the available cartopy projections:

In [3]:
projections = [crs.RotatedPole, crs.Mercator, crs.LambertCylindrical, crs.Geostationary,
crs.AzimuthalEquidistant, crs.OSGB, crs.EuroPP, crs.Gnomonic, crs.PlateCarree,
crs.Mollweide, crs.OSNI, crs.Miller, crs.InterruptedGoodeHomolosine,
crs.LambertConformal, crs.SouthPolarStereo, crs.AlbersEqualArea, crs.Orthographic,
crs.NorthPolarStereo, crs.Robinson]


(  crs.TransverseMercator  and  crs.Stereographic  can also be used, but currently generate warnings.) We can test the different projections by creating a HoloViews Layout of  Feature  elements, each with a different projection:

In [4]:
hv.Layout([gf.coastline.relabel(group=p.__name__)(plot=dict(projection=p()))
for p in projections])

WARNING:root:LayoutPlot04069: None is empty, skipping subplot.

Out[4]:

To change the output projection for a single HoloViews object, we can use the call method and set the projection as a plot option. In this way we can easily compose plots with different output projections:

In [5]:
%output size=200
(features.relabel(group='Mollweide')(plot=dict(projection=crs.Mollweide())) +
features.relabel(group='Geostationary')(plot=dict(projection=crs.Geostationary())))

Out[5]:

Setting the output projection in this way will currently work only with the Matplotlib backend, because Bokeh only supports web Mercator output, but both backends can use incoming data in any of the supported projections, via the  crs  parameter of most GeoViews objects.