Skip to main content

A Python toolkit for producing publication-quality microeconomics diagrams.

Project description

Econ-Viz

PyPI Python License Tests Coverage

A Python toolkit for producing publication-quality microeconomics diagrams. Define utility functions declaratively, solve for consumer equilibria, and export figures as PNG, PDF, or SVG — all in a few lines of code.

Open in Colab

Open the notebook in Colab, then go to File → Save a copy in Drive to keep your own editable version.

Installation

pip install econ-viz

Requires Python 3.12 or later.

Quick Start

import numpy as np
from econ_viz import Canvas, levels, solve
from econ_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, x_label="x", y_label="y",
             title="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")

Cobb-Douglas indifference map with budget line and equilibrium point

CLI

econ-viz ships with a command-line interface for generating diagrams without writing Python.

Commands

Command Description
econ-viz help [<command>] Show help for the CLI or a specific command
econ-viz models List all supported utility models
econ-viz plot ... Generate and export a diagram

Examples

# Cobb-Douglas with equilibrium and budget line
econ-viz plot --model cobb-douglas --alpha 0.5 --beta 0.5 \
              --px 2 --py 3 --income 30 \
              --output cobb_douglas.png

# Parse a LaTeX expression directly
econ-viz plot --latex "x^{0.4} y^{0.6}" \
              --px 2 --py 3 --income 30 \
              --output cd_latex.png

# Leontief with Nord theme and expansion-path ray
econ-viz plot --model leontief --a 1 --b 2 \
              --px 2 --py 3 --income 30 \
              --theme nord --show-ray \
              --output leontief.png

# CES — indifference curves only, no budget or equilibrium
econ-viz plot --model ces --rho -0.5 \
              --x-max 20 --y-max 15 --n-curves 6 \
              --no-budget --no-equilibrium \
              --output ces.png

# Omit --output to open an interactive window
econ-viz plot --model cobb-douglas --px 2 --py 3 --income 30

plot options

Flag Default Description
--model, -m Model name (see econ-viz models)
--latex, -l LaTeX expression (Cobb-Douglas / Leontief / Perfect Substitutes)
--px, --py, --income Prices and budget
--alpha, --beta 0.5 Cobb-Douglas / CES share parameters
--a, --b 1.0 Leontief / Perfect Substitutes / Satiation coefficients
--rho 0.5 CES substitution parameter
--bliss-x, --bliss-y 5.0 Satiation bliss point
--x-max, --y-max 10 Canvas axis limits
--x-label, --y-label x, y Axis labels
--title Figure title
--theme default Colour theme: default, nord
--n-curves 5 Number of indifference curves
--dpi 300 Raster output resolution
--fill off Shade feasible set below the budget line
--show-ray off Draw expansion-path ray through the optimum
--no-budget off Omit the budget line
--no-equilibrium off Omit the equilibrium point
--no-curves off Omit indifference curves
--output, -o Output file; omit to open an interactive window

Utility Models

Cobb-Douglas

from econ_viz.models import CobbDouglas

model = CobbDouglas(alpha=0.3, beta=0.7)

Cobb-Douglas indifference curves

Leontief (Perfect Complements)

from econ_viz.models import Leontief

model = Leontief(a=1.0, b=1.0)   # U = min(ax, by)

Leontief indifference curves

Perfect Substitutes

from econ_viz.models import PerfectSubstitutes

model = PerfectSubstitutes(a=1.0, b=2.0)   # U = ax + by

Perfect substitutes indifference curves

CES

from econ_viz.models import CES

model = CES(rho=-0.5, alpha=0.5)   # elasticity of substitution = 1/(1+rho)

CES indifference curves

Satiation (Bliss Point)

from econ_viz.models import Satiation

model = Satiation(bliss_x=6.0, bliss_y=4.0, a=1.0, b=1.0)

Satiation indifference curves

Quasi-Linear

import numpy as np
from econ_viz.models import QuasiLinear

model = QuasiLinear(v_func=np.log, linear_in="y")   # U = log(x) + y

Quasi-linear indifference curves

Stone-Geary

from econ_viz.models import StoneGeary

model = StoneGeary(alpha=0.5, beta=0.5, bar_x=2.0, bar_y=2.0)

Stone-Geary indifference map with subsistence lines

LaTeX Input

Parse standard LaTeX math expressions directly into model instances:

from econ_viz import parse_latex

cd  = parse_latex(r"x^{0.4} y^{0.6}")
leo = parse_latex(r"\min(2x, 3y)")
ps  = parse_latex(r"2x + 3y")

The parser accepts common preambles such as U(x,y) =, U =, and bare expressions. Unrecognised patterns raise ParseError.

Parsed Cobb-Douglas from LaTeX

Advanced Models

Custom Utility

Wrap any vectorised Python callable as a first-class model. The callable is validated at construction time against a random NumPy mesh-grid.

import numpy as np
from econ_viz.models import CustomUtility

model = CustomUtility(func=lambda x, y: np.log(x) + np.log(y), name="log+log")

Custom utility indifference map

Multi-Good Cobb-Douglas

Model preferences over N goods and project to a 2-D canvas via freeze():

from econ_viz.models import MultiGoodCD

m3   = MultiGoodCD({'x': 0.3, 'y': 0.3, 'z': 0.4})
flat = m3.freeze(z=10.0)   # returns a CustomUtility ready for Canvas
from econ_viz import Canvas, levels, solve

eq   = solve(flat, 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"MultiGoodCD  $z=10$")
cvs.add_utility(flat, levels=lvls)
cvs.add_budget(2.0, 3.0, 30.0, fill=True)
cvs.add_equilibrium(eq)
cvs.save("multigood.png")

Multi-good Cobb-Douglas frozen slice

Solving for Equilibrium

solve() returns an Equilibrium named tuple with fields x, y, and utility:

from econ_viz import solve
from econ_viz.models import CobbDouglas

eq = solve(CobbDouglas(), px=2.0, py=3.0, income=30.0)
print(eq.x, eq.y, eq.utility)

Themes

from econ_viz import Canvas, themes

cvs = Canvas(x_max=20, y_max=15)                    # default theme
cvs = Canvas(x_max=20, y_max=15, theme=themes.nord) # nord theme
Default Nord
Default theme Nord theme

Export

cvs.save("figure.png")    # raster (DPI controlled by Canvas(dpi=300))
cvs.save("figure.pdf")    # vector export for publication workflows
cvs.save("figure.svg")    # scalable vector export

License

MIT © Anthony Sung

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

econ_viz-1.1.0.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

econ_viz-1.1.0-py3-none-any.whl (46.4 kB view details)

Uploaded Python 3

File details

Details for the file econ_viz-1.1.0.tar.gz.

File metadata

  • Download URL: econ_viz-1.1.0.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for econ_viz-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3eb55a2ee4441d6b7a2a3b7d2c27fc42e983379c58e348cae8e3628ef7f5c7df
MD5 b40ba09177cf96506a3c36b6adc33a4a
BLAKE2b-256 6b504e84610b2abc61f56aae88cf92cb26535aa5123d83d756c91bd6ce8a9567

See more details on using hashes here.

Provenance

The following attestation bundles were made for econ_viz-1.1.0.tar.gz:

Publisher: publish.yml on EconViz/econ-viz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file econ_viz-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: econ_viz-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for econ_viz-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a5ad3ecda2b2b5e2f7b7b92e45ea977170098397f736440ecf8c2d68b59fcd3
MD5 d92f41f568ffe238802590ed265eafdb
BLAKE2b-256 472943fe52c9b1e420960600345d566743af475e38ae4395a17a5940d1d4c1f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for econ_viz-1.1.0-py3-none-any.whl:

Publisher: publish.yml on EconViz/econ-viz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page