Skip to content

utility-viz: Python library for microeconomics diagrams

utility-viz

A Python toolkit for producing publication-quality microeconomics diagrams.

Publish Coverage PyPI Python

utility-viz 2.0 is in beta

utility-viz 2.0.0b8 is a pre-release. econ-viz 1.x remains the stable line until 2.0 final is released. Coming from econ-viz? See Migration guide.

from utility_viz import Canvas, levels, solve
from utility_viz.models import CobbDouglas

model = CobbDouglas(alpha=0.5, beta=0.5)
eq = solve(model, px=2.0, py=3.0, income=30.0)
lvls = levels.around(eq.utility, n=5)

cvs = Canvas(
    x_max=20, y_max=15, title=r"Cobb-Douglas $x^{0.5} y^{0.5}$"
)
cvs.add_utility(model, levels=lvls)
cvs.add_budget(2.0, 3.0, 30.0, fill=True)
cvs.add_equilibrium(eq, show_ray=True)
cvs.save("cobb_douglas.png")

Features

  • Eight built-in utility models

    Cobb-Douglas, Leontief, CES, and other textbook utility functions, from perfect substitutes to satiation, ready to plot.

    Model catalogue

  • Automatic equilibrium solving

    Give prices and income and get the consumer's optimal bundle. Interior, kinked, and corner solutions need no manual setup.

    Quick Start

  • Multi-panel teaching figures

    Place diagrams side by side, stacked, or in a grid for before-and-after comparisons, decompositions, or lecture slides.

    Figures & demand diagrams

  • Demand-path diagrams

    Sweep a price or income to trace price- and income-consumption curves, linked to the Marshallian demand curve below.

    Figures & demand diagrams

  • LaTeX parser

    Paste a utility function written in LaTeX and get a ready-to-plot model with its functional form and parameters detected.

    LaTeX parsing

  • Publication-ready export

    Save to PNG, PDF, or SVG in one line. Vector output stays sharp at any size for papers, slides, and the web.

    Export formats

  • Animated GIF sweeps

    Turn parameter, price, or income changes into GIFs so students can watch the equilibrium move with the budget line.

    Animation

  • Notebook widgets

    Tune parameters in Jupyter with sliders or typed values and watch the diagram update as students explore on their own.

    Interactive widgets

  • Analysis helpers

    Compute comparative statics and Slutsky matrices, and check the homogeneity and homotheticity behind every diagram.

    Analysis tools

  • Advanced models

    Wrap any function as a utility model, or project many-good preferences onto a plane to go beyond the textbook cases.

    Advanced models

  • CLI

    Generate diagrams from the terminal without writing Python, and print closed-form Marshallian demand ready for LaTeX.

    CLI reference

Install

uv add --prerelease allow utility-viz

Requires Python 3.10 or later. See Installation for uv and optional extras.

Examples

Every figure in this documentation comes with the script that draws it, sorted into folders by topic. Download them all in one file, with econ-viz.toml, the settings the scripts load (base = "manual").

Download all examples

Comments