import pandas as pd
import holoviews as hv
import geoviews as gv
import geoviews.feature as gf
import cartopy
import cartopy.feature as cf

from geoviews import opts
from cartopy import crs as ccrs

gv.extension('matplotlib', 'bokeh')

gv.output(dpi=120, fig='svg')

Cartopy and shapely make working with geometries and shapes very simple, and GeoViews provides convenient wrappers for the various geometry types they provide. In addition to Path and Polygons types, which draw geometries from lists of arrays or a geopandas DataFrame, GeoViews also provides the Feature and Shape types, which wrap cartopy Features and shapely geometries respectively.


The Feature Element provides a very convenient means of overlaying a set of basic geographic features on top of or behind a plot. The cartopy.feature module provides various ways of loading custom features, however geoviews provides a number of default features which we have imported as gf, amongst others this includes coastlines, country borders, and land masses. Here we demonstrate how we can plot these very easily, either in isolation or overlaid:

(gf.ocean + + gf.ocean * * gf.coastline * gf.borders).cols(3)

These default features simply wrap around cartopy Features, therefore we can easily load a custom NaturalEarthFeature such as graticules at 30 degree intervals:

graticules = cf.NaturalEarthFeature(

(gf.ocean() * * gv.Feature(graticules, group='Lines') * gf.borders * gf.coastline).opts(
    opts.Feature('Lines', projection=ccrs.Robinson(), facecolor='none', edgecolor='gray'))