geoplot icon indicating copy to clipboard operation
geoplot copied to clipboard

New plot types: alternative cartogram types

Open ResidentMario opened this issue 6 years ago • 1 comments

gplt.cartogram currently allows you to plot so-called overlapping non-contiguous cartograms. These cartograms are non-contiguous because the shapes, which are simply scaled in place, are not connected to one another. And they are overlapping because, if the size of the scaled shape exceeds its usual boundaries, it may pass over or under neighboring shapes.

For instance:

import pandas as pd
import geopandas as gpd
import geoplot as gplt
import geoplot.crs as gcrs
import matplotlib.pyplot as plt

obesity_by_state = pd.read_csv(gplt.datasets.get_path('obesity_by_state'), sep='\t')
contiguous_usa = gpd.read_file(gplt.datasets.get_path('contiguous_usa'))
contiguous_usa['Obesity Rate'] = contiguous_usa['state'].map(
    lambda state: obesity_by_state.query("State == @state").iloc[0]['Percent']
)
ax = gplt.cartogram(
    contiguous_usa,
    scale='Obesity Rate', limits=(0.75, 1),
    projection=gcrs.AlbersEqualArea(central_longitude=-98, central_latitude=39.5),
    hue='Obesity Rate', cmap='Reds', k=5,
    linewidth=0.5,
    legend=True, legend_kwargs={'loc': 'lower right'}, legend_var='hue',
    figsize=(12, 12)
)
gplt.polyplot(contiguous_usa, facecolor='lightgray', edgecolor='None', ax=ax)

foo

An overlapping non-contiguous cartogram is easy to implement, because it's a simple scaling operation. There are other more complex cartogram types that are more difficult to implement, but can potentially create more visually interesting results. Some combination of these would be a nice-to-have in geoplot.

Non-overlapping non-contiguous cartograms

Non-overlapping non-contiguous cartograms deal with the "overlapping geometries" problem by adding another form of distortion: the geometries are positioned in space in such a way that they do not overlap (e.g. they are displaced from their true center in some non-overlapping way). This is strictly preferable in cases in which scaled geometries may exceed the original geometries in size.

foo

Contiguous cartograms

Contiguous cartograms retain regional connectivity at the expense of shape (so they are kind of equivalent to cone-versus-cylinder in the projection world).

Screen Shot 2019-07-05 at 3 37 11 PM

Visually stunning when the delta in the data is large. These plots preserve area but sacrifice geography pretty horribly to do so.

Dorling cartogram

Dorling cartograms replace the shape entirely with bubbles (or boxes, or whatever).

dorling

ResidentMario avatar Jul 05 '19 19:07 ResidentMario

agreed.

dquintani avatar Nov 28 '21 14:11 dquintani