Skip to main content

pgfutils

REUSE status SPEC 0 — Minimum Supported Dependencies

The Portable Graphics Format (PGF) is a language for producing vector graphics within TeX documents. There is also a higher-level language TikZ (TikZ ist kein Zeichenprogramm -- TikZ is not a drawing program) which uses PGF.

Since version 1.2, the Python plotting library Matplotlib has included a PGF backend to generate figures ready for inclusion in a TeX document. In order to get consistent figures that fit with the style of the document, this requires some configuration. The aim of pgfutils is to simplify this configuration and allow figures to be easily generated from a Python script.

The module provides two functions which set up and then save the figure. The actual plotting is performed by standard Matplotlib functions. For example, to generate a plot showing the 1st, 3rd, 5th, 7th, 9th and 11th harmonics of an ideal square wave and the resulting sum:

# Set up the figure environment.
from pgfutils import setup_figure, save
setup_figure(width=0.9, height=0.4)

import numpy as np
from matplotlib import pyplot as plt

# Generate a square wave from a few terms of its Fourier series.
f = 3
t = np.linspace(0, 1, 501)
square = np.zeros(t.shape)
for n in range(1, 12, 2):
    # Create this harmonic and plot it as a dashed
    # partially-transparent line.
    component = np.sin(2 * n * np.pi * f * t) / n
    plt.plot(t, component, '--', alpha=0.4)

    # Add it to the overall signal.
    square += component

# Scale the final sum.
square *= 4 / np.pi

# Plot and label the figure.
plt.plot(t, square, 'C0')
plt.xlim(0, 1)
plt.ylim(-1.2, 1.2)
plt.xlabel("Time (s)")
plt.ylabel("Amplitude (V)")

# Save as a PGF image.
save()

Requirements

pgfutils follows SPEC0 when determining supported Python versions. Any minor version of Python released within the 3 years prior to a pgfutils release is supported. As of April 2026, this means Python 3.12 or later.

The only required external dependency is Matplotlib. Any minor version of Matplotlib which was first released within the 24 months prior to a pgfutils release is supported. As of April 2026, this means Matplotlib 3.9.0 or later.

The continuous integration testing checks the combinations of supported Python and Matplotlib version. Older versions of Python or Matplotlib may work, but are not tested and are not supported.

Examples

pgfutils comes with some examples which demonstrate its usage and integration into a build system. Depending on your installation method, these may be present somewhere in your filesystem (e.g., on a Linux system, they might be at /usr/share/matplotlib-pgfutils/examples). They can also be found in the data/share/matplotlib-pgfutils/examples directory.

Documentation

Documentation for pgfutils can be found online at https://matplotlib-pgfutils.readthedocs.io/

Alternatively, you can find the source of this documentation in Markdown format in the doc/ directory of the source:

An example configuration file showing the default settings is given in data/share/matplotlib-pgfutils/pgfutils.cfg.

Unit testing

Test Status codecov

Extensive unit tests are included in the tests/ directory of the source. Each commit to the source repository is automatically tested using GitHub actions. The test coverage (that is, how many of the lines of code in the source were executed during the tests) is monitored by Codecov. The badges above show the status of the last commit made to the source.

You can also run the tests on a local copy of the code. They are designed to be run with the pytest framework and employ the Coverage.py package via the pytest-cov plugin to measure the coverage. If you have these packages installed, run pytest from the top-level directory to execute the tests. A basic test coverage report will be printed on the terminal, and the full report can be viewed by opening the htmlcov/index.html file in your web browser.

License

pgfutils is released under the three-clause BSD license. The terms of this license can be found in the LICENSES/BSD-3-Clause.txt file in the source, or online at https://opensource.org/licenses/BSD-3-Clause

The Cotham Sans font used in some unit tests is copyright (c) 2015 Sebastien Sanfilippo and is licensed under the SIL Open Font License, Version 1.1. The license can be found in the source at LICENSES/OFL-1.1.txt or online at https://scripts.sil.org/OFL and the font itself can be found at https://github.com/sebsan/Cotham

pgfutils supports the REUSE initiative. All files either have with SPDX-compliant license identifiers in their headers, or have a REUSE.toml manifest file accompanying them.

Metadata

Release files for matplotlib-pgfutils 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for matplotlib-pgfutils 2.0.1
File Size Uploaded
matplotlib_pgfutils-2.0.1.tar.gz 328.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for matplotlib-pgfutils 2.0.1
File Interpreter ABI Platform
matplotlib_pgfutils-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 345.0 kB

Release files / matplotlib_pgfutils-2.0.1.tar.gz

Download URL matplotlib_pgfutils-2.0.1.tar.gz
Size 328.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3bedd54a17681764f72876f47101b7dafadc8c2bf5586a976889769328bff43b
BLAKE2b-256 checksum
How to use checksums
0b7b62d5cb3f675bdfdc324ee63dfcd27c08229e6e540f47806a9b90d70b5322
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release files / matplotlib_pgfutils-2.0.1-py3-none-any.whl

Download URL matplotlib_pgfutils-2.0.1-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57663bac6f4212f0da4818f3890ebddd12f3ad91e3ca706050a5b5b8eb487ab4
BLAKE2b-256 checksum
How to use checksums
8e46661122e765c9b632023c210ef4047070e8b11a3fa47cf513f7322847b02b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 30, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page