• title: Interactive maps with Python made easy: Introducing Geoviews
  • date: 2019-07-28
  • modified: 2019-08-13
  • tags: python, geoviews, holoviews, bokeh, maps, pyviz, holoviz
  • Slug: interactive-maps-made-easy-geoviews
  • Category: Python
  • Authors: MC
  • Summary: Do you want to build map visualizations in Python? Look no further than GeoViews. It is not only super simple to use but also offers several interactive features that make your visualization stand out. Using geo spatial data from our bike rental data set we explore some of the possibilities.

Get this post as an interactive Jupyter Notebook and execute the code via Binder: Binder


Map visualizations are an effective way to gain insights from geo-spatial data. In a previous post we looked at rental bike data in Cologne. For that, we used the Basemap extension for Matplotlib. However, using Matplotlib often feels cumbersome and the output is static. Moreover, the charts look kind of outdated. In a follow up post we dealt with these issues by introducing bokeh as an alternative. The result was a good looking visualization with lots of interactivity.
However, when thinking about visualization libraries in Python the whole landscape is way wider:

Visualization Landscape in Python

Source: Pyviz (Nicolas P. Rougier) adaption of Jake VanderPlas original chart

While this means that there is tool for each need the bulk of options can also be overwhelming. This article deals with the problem and comes up with a great solution: the PyViz initiative which

"[...] [steers] users to a smaller number of starting points without cutting them off from important functionality [...]".

One of the results of the initiative is the GeoViews library:

GeoViews is a Python library that makes it easy to explore and visualize geographical, meteorological, and oceanographic datasets, such as those used in weather, climate, and remote sensing research.

It is very high-level so that you can do great things in only a few lines of code. Moreover, it builds upon bokeh so that you have interactivity. Lastly, it shares a consistent and simple syntax with all other PyViz libraries.
In the following, we will again use our Cologne bike rental data to demonstrate the elegance of GeoViews. We will dive into using shapefiles, plotting geo locations and adding several levels of interactivity. Get the data here and follow along.

Setting up the environment

As usual, we start by importing the relevant libraries. Also, we tell GeoViews to use bokeh for chart outputs and display these inside our notebook:

In [16]:
# coding: utf-8
import pandas as pd
import numpy as np
import geoviews as gv
#from bokeh.io import output_notebook
pd.set_option('display.max_columns', 100)