Create a choropleth map with geoviews and geopandas. Working geoviews installation instructions as of May 2021.
Choropleth maps can be used to immediately convey important information about a geographical dataset.
Like heat maps, they show the local variations of a measurement, such as population density. However, while heat maps average measurements in arbitrary bins, choropleth maps do that according to predefined boundaries, such as country and state frontiers.
In this post, you will use state-of-the art python visualization libraries to draw choropleth maps. You will learn:
First, Install Anaconda if not yet done.
Then, create a new conda environment for this exercise, named geoviews:
conda create -n geoviews python=3.7
May 2021: Note that we do want to use python 3.7, to avoid a temporary conda dependency issue with later versions of python.
conda activate geoviews
And install geoviews :
conda install -c pyviz geoviews
This is going to take a few minutes, please be patient.
Finally, here are the files needed for this tutorial (jupyter notebook, input dataset), in case you need them.
By installing geoviews, we have actually installed a large number of python packages, that are (or might be) needed for geographical data analysis and visualization.
Here is a simplified description of the dependencies between some of these packages:
This might seem a bit complicated, and indeed it is!
Currently, at the end of 2019, the landscape of python visualization is transforming rapidly, and it can be quite difficult to choose and learn the right tools. Personally, here's what I'm looking for:
Many times, I use bokeh directly, like in Show your Data in a Google Map with Python or Interactive Visualization with Bokeh in a Jupyter Notebook. But making a single plot in bokeh can require a dozen lines of code or more.
Holoviews, which can be used as a high-level interface to bokeh or matplotlib, makes it easy to create complex plots in just two lines of code, and is thus addressing point 1.
When I need to display big data, I use datashader, a library that compresses big data into an image dynamically before sending it to a bokeh plot. Again, bokeh and holoviews are the way to go here.
In june 2019, the holoviz project was launched. The holoviz team is packaging the tools I need in the pyviz conda repo, and seems to share my views of how data visualization in python should evolve. So I'm now using holoviz as a main entry point to visualization. If you want to know more about this project, you can refer to their FAQ.
import geoviews as gv
import geoviews.feature as gf
import xarray as xr
from cartopy import crs