Animation
econ-viz v1.4.0 adds a lightweight GIF workflow built around Animator. The API stays close to normal plotting: you write a frame factory that returns a fresh Canvas or Figure, then sweep a numeric frame sequence and save the result as a GIF.
Install
If you also want notebook widgets, install:
Minimal example
import numpy as np
from econ_viz import Canvas, levels, solve
from econ_viz.animation import Animator
from econ_viz.models import CobbDouglas
def draw(px: float) -> Canvas:
model = CobbDouglas(alpha=0.5, beta=0.5)
eq = solve(model, px=px, py=2.0, income=20.0)
lvls = levels.around(eq.utility, n=5)
return (
Canvas(x_max=14, y_max=12, x_label="X_1", y_label="X_2", title="Price sweep")
.add_utility(model, levels=lvls)
.add_budget(px=px, py=2.0, income=20.0, fill=True)
.add_equilibrium(eq, show_ray=True, drop_dashes=True)
)
Animator(draw, frames=np.linspace(1.0, 6.0, 45)).save(
"price_sweep.gif",
fps=12,
dpi=120,
)
Teaching sweeps
The local example script at examples/animation.py now generates three separate sweep families:
- Parameter sweeps: move one utility-function parameter while holding prices and income fixed.
- Price sweeps: hold the utility function fixed and sweep
p_xwhile holdingp_yfixed. - Income sweeps: hold the utility function and prices fixed and move only income.
- Budget-only sweeps: remove the utility layer entirely so students can isolate budget-line motion.
The docs site embeds the same GIF assets directly, so what you see here matches the locally generated examples.
Parameter sweeps
These animations answer “how does the preference map itself change?”
alpha while beta = 1 - alpha.
rho to change curvature and substitutability.
a with b fixed.
a with b fixed to move the kink path.Price sweeps
These animations answer “how does equilibrium move when the budget line rotates?” The key design choice in v1.4.0 is that the utility function is held fixed, and the background indifference-map levels are also held fixed.
p_y fixed.
Income sweeps
These animations answer “how does equilibrium move when the budget line shifts in parallel?”
Export notes
Animator.save()uses Pillow, so noffmpegdependency is required.- GIF frames are composited onto white before export to prevent frame stacking artifacts.
fps,dpi, andloopare configurable per animation.