GeoViews¶
GeoViews makes it easy to explore and visualise geographic, meteorological and oceanographic data sets. GeoViews is based on HoloViews and complements its visualisation of multidimensional data with geographic plot types based on Cartopy.
Installation¶
If Cartopy is already installed, GeoViews can be installed with pipenv:
$ pipenv install geoviews
Examples¶
GeoViews works well with Iris and xarray libraries for multidimensional arrays as stored in netCDF files. However, GeoViews also accepts data as NumPy arrays and pandas data frames. In either case, the data can be stored in its original, native format and packaged into a HoloViews or GeoViews object that enables interactive visualisations.
xarray example¶
For the following example we also need xarray. It can be installed with Spack with:
$ spack install py-xarray
[1]:
import geoviews as gv
import geoviews.feature as gf
import xarray as xr
from cartopy import crs
gv.extension("bokeh", "matplotlib")
[2]:
(gf.ocean + gf.land + gf.ocean * gf.land * gf.coastline * gf.borders).opts(
"Feature", projection=crs.Geostationary(), global_extent=True, height=325
).cols(3)
[2]:
We use geoviews-sample-data.zip as sample data and unpack it as the data
directory.
[3]:
!curl http://assets.holoviews.org/geoviews-sample-data.zip --output geoviews-sample-data.zip
!unzip geoviews-sample-data.zip
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 6246k 100 6246k 0 0 5679k 0 0:00:01 0:00:01 --:--:-- 5694k
Archive: geoviews-sample-data.zip
inflating: ensemble.nc
inflating: ensembles.nc
inflating: pre-industrial.nc
[4]:
dataset = gv.Dataset(xr.open_dataset("./ensemble.nc"))
ensemble = dataset.to(
gv.Image, ["longitude", "latitude"], "surface_temperature"
)
gv.output(
ensemble.opts(
cmap="viridis", colorbar=True, fig_size=200, backend="matplotlib"
)
* gf.coastline(),
backend="matplotlib",
)
GeoPandas example¶
GeoViews also natively supports GeoPandas data structures, so we can easily display shapefiles and Choropleth:
[4]:
import geopandas as gpd
gv.Polygons(
gpd.read_file(gpd.datasets.get_path("naturalearth_lowres")),
vdims=["pop_est", ("name", "Country")],
).opts(tools=["hover"], width=600, projection=crs.Robinson())
/tmp/ipykernel_88986/2104909695.py:5: FutureWarning: The geopandas.dataset module is deprecated and will be removed in GeoPandas 1.0. You can get the original 'naturalearth_lowres' data from https://www.naturalearthdata.com/downloads/110m-cultural-vectors/.
gpd.read_file(gpd.datasets.get_path("naturalearth_lowres")),
[4]: