Using both color and opacity gives us the ability to simultaneously visualize two features on the choropleth. I typically use color to visualize the main feature (like, average height) and opacity to visualize how many measurements were in that group.

Data for different areas might be sampled at different times, and TimeDynamicGeoJson can deal with that. This means that there is no need to resample the data, as long as the number of datapoints isn't too large for the browser to deal with.

To simulate that data is sampled at different times we random sample data for n_periods rows of data and then pick without replacing n_sample of those rows.

We see that we generated two series of data for each country; one for color and one for opacity. Let's plot them to see what they look like.

In [9]:

ax=df.plot()

Looks random alright. We want to map the column named color to a hex color. To do this we use a normal colormap. To create the colormap, we calculate the maximum and minimum values over all the timeseries. We also need the max/min of the opacity column, so that we can map that column into a range [0,1].