SVG diagram generator

create_svg_diagrams.py generates two production-function diagrams:

  • standard_production_function.svg
  • electricity_distribution_production_function.svg

The diagrams are defined directly in the script; no model run or input data is required.

Prerequisites

  • Python 3 with pip.
  • The Python packages graphviz and matplotlib. The script currently imports matplotlib.pyplot, so Matplotlib is required even though Graphviz renders the diagrams.
  • The system Graphviz installation, with its dot executable available on PATH.

The Python graphviz package and the system Graphviz renderer are separate installations. Installing the Python package alone does not provide dot. See the Python Graphviz installation guide.

Install system Graphviz

Install Graphviz in the environment where the script runs. For a devcontainer, run the installation commands in its terminal.

Debian, Ubuntu, or the G-Cubed devcontainer

sudo apt-get update
sudo apt-get install -y --no-install-recommends graphviz

A manual installation inside a container may need to be repeated after the container is recreated.

macOS with Homebrew

brew install graphviz

The Graphviz download page lists these package manager options and installers for other operating systems.

Windows

Install Graphviz using an installer from the official download page. Add its bin directory, typically C:\Program Files\Graphviz\bin, to PATH if the installer does not do so. Restart the terminal and IDE after changing PATH.

Install Python packages

Use the same Python interpreter that runs the script in your IDE. The commands below use python; substitute python3 or the full interpreter path as needed.

python -m pip install graphviz matplotlib

See the Matplotlib installation guide for its supported installation options.

For an isolated installation, or if your system Python rejects package installation with an externally-managed-environment error, first create a virtual environment from the documentation-preview repository root:

python -m venv .venv

Activate it with source .venv/bin/activate on Linux/macOS, or .\.venv\Scripts\Activate.ps1 in Windows PowerShell. Then run the package installation command above and select that interpreter in your IDE.

Verify prerequisites and run

Check both the system executable and Python imports in the terminal that will run the script:

dot -V
python -c "import graphviz, matplotlib.pyplot; print('Python dependencies available')"

dot -V should print a Graphviz version. From the documentation-preview repository root, run:

cd "docs/assets/images/diagram generator"
python create_svg_diagrams.py

Both SVGs are written to the current working directory. These commands save them beside the script. Running the script by absolute path from another directory saves them in that directory instead. Existing SVGs with the same names are overwritten. Successful execution does not print a completion message; open the generated SVGs in a browser or your IDE to inspect them. Temporary Graphviz source files are removed after successful rendering.

Troubleshooting

  • ExecutableNotFound, No such file or directory: 'dot', or failed to execute ... dot: install system Graphviz and check dot -V. Reinstalling the Python package alone will not resolve this error. If dot -V works in a terminal but the IDE still fails, restart the IDE and check that it runs in the same environment with the same PATH.
  • ModuleNotFoundError: No module named 'graphviz' or 'matplotlib': run python -m pip install graphviz matplotlib with the interpreter that executes the script, then repeat the import check above.
  • SVGs appear to be missing: check the working directory used by the terminal or IDE; output paths are relative to that directory.