Skip to main content

A Matplotlib-like interface for generating Tikz and Pgfplots figures

Project description

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.

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

pykz-0.2.1.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pykz-0.2.1-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file pykz-0.2.1.tar.gz.

File metadata

  • Download URL: pykz-0.2.1.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pykz-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6ef9fb75cec7d64fc3bd2c01159c41aac0651a57a3ab0c6b010e7ab83f744e72
MD5 b6ba7fe9294218f0a2acb4e4972983f3
BLAKE2b-256 2c05d1eca4d480bfe9a53f176157b3d335887d685230b6f87160dc00ea2ef1e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykz-0.2.1.tar.gz:

Publisher: wheels.yaml on Mathijssch/pykz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pykz-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pykz-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pykz-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afd728f5be98ea3f75216532e66f8a88207f7f0f3f82fd6a3879c460af1b932b
MD5 4c232b5a3c396234912623f29cc27a7a
BLAKE2b-256 c09d563ae4c6ee52ca2a6a2edacf9a3bd7d771049cc937274fea7bb0de4a3320

See more details on using hashes here.

Provenance

The following attestation bundles were made for pykz-0.2.1-py3-none-any.whl:

Publisher: wheels.yaml on Mathijssch/pykz

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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