Skip to main content

Pykz

A Python library to generate tikz code

Examples PyPI GitHub license

Generate beautiful, publication-ready figures with the power of Tikz and pgfplots, with a comfortable, familiar Python syntax.

pykz aims to provide a syntax similar to matplotlib, but with the possibility of directly generating (and controlling!) your tikz code.

The benefit over alternatives like tikzplotlib is that pykz was designed explicitly with pgfplots in mind, whereas the goal of tikzplotlib is to map matplotlib concepts to pgfplots. The latter is arguably more convenient if you already have code for matplotlib, but it often still requires manual tweaking to the resulting tex-files. pykz aims to provide more control over the final output directly in Python, so no manual tweaking is required afterwards.

Usage

Basic plotting

Pykz has a simple, matplotlib-like interface for basic plotting.

import numpy as np
import pykz

x = np.linspace(0, 10, 100)
y = np.sin(x)

pykz.plot(x, y)

# (Optional) save the tikz code to a file.
pykz.save("test-basic-plot.tex")

# Save the Tikz code to a temporary file, compile it, and open the pdf in the default viewer.
pykz.preview()
Sample output

Using Tikz primitives

Alternatively, you can use standard TikZ drawing primitives, without using pfgplots. Options passed to the TikZ command are passed as keyword arguments.

import pykz

rect = pykz.rectangle((-1, -1), (1, 1))
circle = pykz.circle((2, 0), (1), fill="red")

rect2 = pykz.rectangle((1, 1), (2, 3), fill="cyan")

# Dump the generated tikz code to the stdout.
print(pykz.dumps())

# Save the Tikz code to a temporary file, compile it, and open the pdf in the default viewer.
pykz.preview()

out:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}
\draw(-1.000000000, -1.000000000) rectangle (1.000000000, 1.000000000);
\draw[fill=red](2.000000000, 0.000000000) circle (1);
\draw[fill=cyan](1.000000000, 1.000000000) rectangle (2.000000000, 3.000000000);

\end{tikzpicture}
\end{document}
Sample output

More examples can be found in the online documentation.

Metadata

Release files for pykz 0.2.3

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

Source distribution (sdist)

Source distribution for pykz 0.2.3
File Size Uploaded
pykz-0.2.3.tar.gz 31.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pykz 0.2.3
File Interpreter ABI Platform
pykz-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 70.3 kB

Release files / pykz-0.2.3.tar.gz

Download URL pykz-0.2.3.tar.gz
Size 31.8 kB
Tags Source
SHA-256 checksum
How to use checksums
aef4a7a278ac3f5cf27d54b148cf4336ddb25ed2b6d4a525e51ffdbd97b700c5
BLAKE2b-256 checksum
How to use checksums
d961a0aca560c609fac26e3d7a7dfa19dc3a8764c4be8774689117cdfeef9de2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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 Nov 4, 2025.

Transparency log

Release files / pykz-0.2.3-py3-none-any.whl

Download URL pykz-0.2.3-py3-none-any.whl
Size 38.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
adc8f6affe74fca9535746a4a56be86efbaf9df13c1e583d65bcfff0996e9d73
BLAKE2b-256 checksum
How to use checksums
6151c736a6ef18fe5e79d562fd3f1f01e5a6120c3514b7d84c70a50832dbae7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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 Nov 4, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.3 This release

2 release files

0.2.1

2 release files

0.1.4

2 release files

0.1.3

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