Skip to content

principle-viz: Principles of Economics market diagrams in Python

principle-viz

Python package for Principles of Economics market analysis and diagrams.

PyPI Python License

from principle_viz.core.equilibrium import solve_equilibrium
from principle_viz.core.line import Line
from principle_viz.plot.figure import MarketFigure

# P = 10 - Q
demand = Line.from_inverse(10.0, -1.0)
# P = 2 + Q
supply = Line.from_inverse(2.0, 1.0)
# Q* = 4, P* = 6
eq = solve_equilibrium(demand, supply)

fig = MarketFigure(
    x_max=12, y_max=12, title="Basic Equilibrium"
)
fig.add_curves(demand, supply, q_max=10)
fig.add_equilibrium(eq)
fig.finalize()
fig.save("basic_equilibrium.png")
fig.close()

Features

  • Market equilibrium

    Solve equilibrium from linear demand and supply, or from discrete unit schedules.

  • Comparative statics

    Shift demand or supply and see the move from the old equilibrium to the new one.

  • Taxes and subsidies

    Fixed, per-unit and ad valorem taxes, with legal incidence on buyers or sellers.

  • Price controls

    Price ceilings, price floors and the minimum wage, with the shortage, surplus or unemployment marked.

  • Welfare decomposition

    Consumer and producer surplus, tax revenue and deadweight loss.

  • Trade, externalities and more

    Tariffs and quotas, externalities, common resources, public goods, loanable funds, the PPF and elasticity.

  • Market aggregation

    Sum individual curves or schedules horizontally into market demand and supply.

  • CLI

    Run equilibrium, tax, subsidy and trade analyses from the terminal, with JSON output.

Install

uv add principle-viz

Requirements

  • Python 3.10 or later.
  • mosaickit, which uv installs automatically.

See Installation for the development setup, or go straight to the Quick start.

Documentation

The following chapters cover principle-viz 0.14.0.

Examples

The scripts that draw the figures in the manual and on these pages come as one zip, sorted by topic.

Download all examples

Comments