Skip to main content

Typst backend for matplotlib (Python visualization library).

Project description

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

In order to render image with mpl_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
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>

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

mpl_typst-0.1.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

mpl_typst-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file mpl_typst-0.1.0.tar.gz.

File metadata

  • Download URL: mpl_typst-0.1.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.5

File hashes

Hashes for mpl_typst-0.1.0.tar.gz
Algorithm Hash digest
SHA256 113f40274ea30a4a1ae598659410bbd590a6f92fdd09004fd210bc9eeb4d158d
MD5 4f75817fe0af157e54e627d93910a187
BLAKE2b-256 1f9f52bf4769a2057d6ac76a70f2f15d37d18a16d2370fafefbf40338669a80b

See more details on using hashes here.

File details

Details for the file mpl_typst-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mpl_typst-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.5

File hashes

Hashes for mpl_typst-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6bbe4eb8c9a18f982f60d3256d7ba952a64e854e25d5a54146d63fdc299e2f7c
MD5 c4b2069512df5ae7c4cd5705ff0b8bf3
BLAKE2b-256 af539f7384c03888e83445496c0e3e1f891dd2c56aae2664a2688c2b8d1a55a1

See more details on using hashes here.

Supported by

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