This is a Python package to compute cartograms from geopandas.GeoDataFrames
, using the algorithm presented in Dougenik et al. (1985). It is the ‘sister project’ and Python implementation of our QGIS plugin which continues to be available.
cartogram
is available from the PyPi package
repository, install it, for instance, using pip
:
pip install cartogram
You will need a polygon data set in any format readable by
geopandas
that
features a numeric attribute column to use as the relative target values to base
the cartogram distortion on.
If you want to have a quick try-out, see the population data for Austrian
provinces in the tests/data
directory of this repository.
import cartogram
import geopandas
df = geopandas.read_file("input-data.gpkg")
c = cartogram.Cartogram(df, column="population")
c.to_file("output-data.gpkg")
Find more detailed examples and an API reference at https://python-cartogram.readthedocs.io/.