Skip to main content

A Matplotlib-like interface for generating Tikz and Pgfplots figures

Project description

Pykz

A Python library to generate tikz code

Static Badge PyPI - Python Version

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 pykz was designed explicitly with pgfplots in mind, whereas the goal of tikzplotlib is to map matplotlib concepts to pgfplots. This 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
For more examples, visit 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.1.3.tar.gz (165.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.1.3-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pykz-0.1.3.tar.gz
  • Upload date:
  • Size: 165.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for pykz-0.1.3.tar.gz
Algorithm Hash digest
SHA256 eb576acd2e11f10b8fef39fad75ca84c713f857877345ce2da6fbf63b3d2514e
MD5 b9e75c2d9bafe0b50df35001342d7893
BLAKE2b-256 edd10e6f9a903c19c61f6fd2c2df764940decf7116dd1eccd8b7d9a6884d493e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pykz-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for pykz-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b3ea48b3c8bbdb403b6cba1fe457c02c2525f833525571b556e88413a13b7248
MD5 cba41c2dcb874ee18a2849316d97f27c
BLAKE2b-256 5065bbc342fca5d019e78fb86fdf21b9f7c0b0e41e55e49e50ba3b6c9a5322db

See more details on using hashes here.

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