Skip to main content

Linting and testing Nightly

Typst Matplotlib Backend

Typst backend for matplotlib (Python visualization library).

Overview

At the moment, Typst supports main vector and raster image formats. Namely, images in PNG, JPEG, GIF, or SVG format can be easily emplaced in a document with Typst. However, it is not possible to keep metadata and annotations. These are mandatory in order to allow a reader to select and interact with vector content (e.g. text) on images. Although SVG can contain text metadata in principle, Typst does not support this feature at the moment but still it is able to render SVG as a vector content.

This package solves this problem for matplotlib users. Basically, this project implements a custom render (or backend) for matplotlib which generates typ-file containing Typst markup. Generated markup file can be later included in the original markup so that the resulting PDF will have interactable content. Matplotlib exploits exactly the same strategy in order to generate PGF-files — a LaTeX markup itself — which can be included into LaTeX markup directly.

Usage

To export a figure using typst, just add

import matplotlib
import mpl_typst

# your drawing code

fig.savefig('figure.typ')

You may call plt.show() afterwards, which displays the figure using your default agg backend.

In order to set the mpl_typst module as default backend (which deactivates interactivity, but also renders SVG, PNG and PDF using typst) one can import mpl_typst.as_default module in order to use mpl_typst backend by default.

import mpl_typst.as_default

Or one can configure it manually.

import matplotlib as mpl
import mpl_typst
mpl.use('module://mpl_typst')

Also, it is possible to use rendering context as usual to override backend.

import matplotlib as mpl
import mpl_typst
with mpl.rc_context({'backend': 'module://mpl_typst'}):  # or mpl_typst.BACKEND
    ...

Next, you can save your figure to typ as usual.

fig, ax = plt.subplots()
...
fig.savefig('line-plot-simple.typ')

As soon as you get a typ-file you can included it directly to figure function and adjust figure time.

#figure(
  include "line-plot-simple.typ",
  kind: image,
  caption: [Simple line plot],
  placement: top,
) <line-plot-simple>

Development Notes

Generated Typst drawing elements use Matplotlib coordinates that have already been normalized to the page's top-left origin. For this reason, every generated Typst place() call must be explicitly anchored with top + left. Do not rely on Typst's default placement alignment; it depends on surrounding document context and can shift clipped drawing elements when a generated figure is included with figure(kind: image).

Release files for mpl-typst 0.3.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 mpl-typst 0.3.1
File Size Uploaded
mpl_typst-0.3.1.tar.gz 22.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mpl-typst 0.3.1
File Interpreter ABI Platform
mpl_typst-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 45.6 kB

Release files / mpl_typst-0.3.1.tar.gz

Download URL mpl_typst-0.3.1.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1a1476dcc6be6f242abdecc633687cc09b3e12579caad6058484e5dcbe28486f
BLAKE2b-256 checksum
How to use checksums
62be8f6ffaf84c6eed6ab51456565a6720998bc80e2dffe261a820f7ae917bbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jun 27, 2026.

Transparency log

Release files / mpl_typst-0.3.1-py3-none-any.whl

Download URL mpl_typst-0.3.1-py3-none-any.whl
Size 23.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b7c735d89967a897dd8efaa8978183b7425523c4a79e1fc66a9a67850d13509
BLAKE2b-256 checksum
How to use checksums
23e1a694d18b31d2e44fa71a6ad01bfecee35f97bd65321bc00704cca5f8bc7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jun 27, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.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