Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New plot types: alternative cartogram types #150

Open
ResidentMario opened this issue Jul 5, 2019 · 1 comment
Open

New plot types: alternative cartogram types #150

ResidentMario opened this issue Jul 5, 2019 · 1 comment
Labels

Comments

@ResidentMario
Copy link
Owner

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

@dquintani
Copy link

agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants