Note
Click here to download the full example code
Density Field Animation¶
Animates the internal density field using animate_density_field.
Build the cartogram with snapshot
import carto_flow.data as examples
import carto_flow.flow_cartogram as flow
from carto_flow.flow_cartogram.animation import animate_density_field
gdf = examples.load_us_census(population=True)
cartogram = flow.morph_gdf(
gdf,
"Population",
options=flow.MorphOptions.preset_balanced().copy_with(
n_iter=250,
snapshot_every=5,
area_scale=1e-6,
show_progress=False,
save_internals=True,
),
)
Animate the morphing snapshots.
anim = animate_density_field(
cartogram,
duration=2.0,
fps=15,
show_axes=False,
figsize=(8, 5),
density=flow.DensityPlotOptions(
colorbar_kwargs={"shrink": 0.7},
normalize="ratio",
),
)
Total running time of the script: ( 0 minutes 8.162 seconds)
Download Python source code: plot_flow_animation_density.py
Download Jupyter notebook: plot_flow_animation_density.ipynb