Skip to content

Note

Click here to download the full example code

Velocity Field Animation

Animates the internal velocity field using animate_velocity_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_velocity_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_velocity_field(
    cartogram,
    duration=2.0,
    fps=15,
    show_axes=False,
    figsize=(8, 5),
    velocity=flow.VelocityPlotOptions(colorbar_kwargs={"shrink": 0.7}, color_by="direction", velocity_scale=3),
)

Total running time of the script: ( 0 minutes 8.864 seconds)

Download Python source code: plot_flow_animation_velocity.py

Download Jupyter notebook: plot_flow_animation_velocity.ipynb

Gallery generated by mkdocs-gallery