Note
Click here to download the full example code
Dot Density Cartogram¶
A dot density cartogram of poverty levels across US states.
Uses carto_flow.proportional_cartogram.plot_dot_density.
Load dataset and plot dot density cartogram.
import matplotlib
matplotlib.use("Agg")
import carto_flow.data as examples
import carto_flow.proportional_cartogram as pc
us_states = examples.load_us_census(population=True, poverty=True, simplify=1000)
result = pc.plot_dot_density(
us_states,
columns=["Above Poverty Level", "Below Poverty Level"],
n_dots=1000,
normalization="maximum",
alpha=[0.1, 1.0],
palette={"Below Poverty Level": "#ff0000", "Above Poverty Level": "#000000"},
)
result.ax.axis("off")

Out:
/home/runner/work/carto-flow/carto-flow/.venv/lib/python3.12/site-packages/geopandas/_compat.py:7: DeprecationWarning: The 'shapely.geos' module is deprecated, and will be removed in a future version. All attributes of 'shapely.geos' are available directly from the top-level 'shapely' namespace (since shapely 2.0.0).
import shapely.geos
(np.float64(-2455013.9058703315), np.float64(2343542.8991046646), np.float64(-1844263.887562148), np.float64(1479814.4164355285))
Total running time of the script: ( 0 minutes 9.705 seconds)
Download Python source code: plot_dot_density_cartogram.py