Skip to main content

TikzPlot

A clean version of PltToTikz, this time as Python package. Easy to use: only replace import matplotlib.pyplot with this library.

Please report any bugs or unexpected behaviour in Issues. Examples may be found in repository under tests/ directory.

Why use pgfplots instead of matplotlib?

  • Tikz/pgfplots is a LaTeX package, so it is easy to integrate into your LaTeX document, and the fonts will match your document, rescaling will not affect font sizes.
  • Tikz/pgfplots graph is easy to edit, especially if only minor style changes are needed, while matplotlib requires re-running the code to generate a new graph.
  • Full math mode is supported, so you can use LaTeX math in your labels, legends, etc.

Why use this package instead of other available?

  • It is easy to use, with code being very similar to matplotlib and only minor changes are needed to switch from matplotlib to this package.
  • It relies on frontend commands, which are less likley to change in matplotlib, so new updates do not break it.
  • It generates clean and readable Tikz code, which is easy to edit and understand. Code is also efficient and does not contain unnecessary commands, which is important escpecially for large graphs.
  • If you use LLMs to generate pgfplots code, you will often get code that is not compilable, since for more complex requirements, LLMs make up commands that do not exist. This package covers many use cases and generates compilable code.

Installation

PyPI: pip install tikzplot42. Alternativley, download this package and install using: pip install [path], where [path] is the path to the directory, containing pyproject.toml.

Python usage

Instead of using import matplotlib.pyplot (as plt), use import tikzplot.plots (as plt).

LaTeX requirements

All required packages are automatically detected and can be printed at save using kwarg print_requirements=True (for standalone files, preambule is automatically added).

  • \usepackage{tikz},
  • \usepackage{pgfplots},
  • \pgfplotsset{compat=1.18} (may be lower, but compilation is not guaranteed),
  • \usepgfplotslibrary{fillbetween} (if you use fill-between plots),
  • \usepgfplotslibrary{groupplots} (recommended for best results, enabled by default, may be avoided by setting TikzConfig USE_GROUPPLOTS=False),
  • \usepackage{xcolor} (recommended for best colors, works without but needs change of TikzConfig USE_XCOLOR=False),
  • \usepgfplotslibrary{polar} required for polar axis,
  • \usepgfplotslibrary{smithchart} required for Smith chart axis,
  • \usetikzlibrary{patterns.meta} for hatch patterns (available for fill_between, hist and axvspan/axhspan).

Export using plt.savefig("example_graph.tex") (recommended) or plt.show(). Then use the generated file as \input{example_graph.tex}.

Currently implemented:

Some basic plot commands are already implemented with commonly used arguments:

Plotting

  • plot(),
  • scatter(),
  • quiver(),
  • streamplot(),
  • contour(),
  • contourf(),
  • loglog(),
  • semilogx()/semilogy(),
  • errorbar(),
  • stem(),
  • fill_between(),
  • hlines()/vlines(),
  • hist(),
  • bar()/barh(),
  • bar_label(),
  • stackplot(),
  • step(),
  • imshow(),
  • matshow(),
  • text(),
  • bxp() (without notches),
  • boxplot() (without notches),
  • violin(),
  • violinplot(),
  • pie(),
  • pie_label() (basic only for now),
  • eventplot(),
  • ecdf() (empirical cumulative distribution function),
  • magnitue_spectrum(),
  • phase_spectrum(),
  • angle_spectrum(),
  • specgram(),
  • xcorr(),
  • acorr(),
  • psd() (power spectral density),
  • csd() (cross spectral density),
  • cohere(),
  • magnify() (used to magnify part of a plot, but Tikz cannot handle fill_between if this one is used, which is a long known issue),
  • axvline()/axhline(),
  • axvspan()/axhspan() (background span).

3D plotting

  • plot(),
  • scatter(),
  • errorbar(),
  • fill_between(),
  • plot_wireframe(),
  • plot_surface(),
  • bar3d(),
  • text().

Figures

  • plt.figure() (currently only to give you figure object or to set figsize),
  • plt.subplot(), plt.subplots() (with sharex/sharey fully implemented, projection polar and 3d with basic support),
  • set_size_inches(),
  • delaxes().

Styles

If axes and plot have different name for command with same effect, both are implemented (e.g. plt.xlim() and ax.set_xlim()).

  • grid(),
  • xlabel()/ylabel(),
  • xlim(), ylim(),
  • xscale("log")/yscale("log"),
  • xticks()/yticks(),
  • ax.set_xticklabels()/ax.set_yticklabels(),
  • legend() (basic position control),
  • ax.twinx(),
  • ax.set(),
  • ax.tick_params(),
  • tight_layout() (requires local pdflatex),
  • subplot_mosaic() (requires TikzConfig USE_GROUPPLOTS=True),
  • ax.inset_axes() (requires TikzConfig USE_GROUPPLOTS=True).

There is a limited support for built-in styles (e.g. plt.style.use("default")), you may also define your own style using plt.style.set_profile(). Currently supported features are: color cycle (hex colors sequence), line width (in pt), grid (with matplotlib kwargs), background (latex style key=value), additional settings (raw latex code for optional arguments to axis: key=value).

Supported common **kwargs

Some commonly used kwargs are listed below, check options for each command.

  • color/c,
  • linestyle/ls,
  • linewidth/lw,
  • fmt,
  • marker,
  • marksize/ms,
  • alpha,
  • label,
  • facecolor/fc,
  • edgecolor/ec,
  • hatch,
  • hatch_color,
  • hatch_linewidth.

Colorbars

Colorbars and colormaps are implemented a bit differently than in matplotlib (simplified):

  • if you use imshow(), you may use its return in Colorbar() (which you have to import as from tikzplot import Colorbar),
  • you may use Colorbar(axis, cmap, lower, upper, ...) for manual colorbar. Additional kwargs may also be used by imshow() return,
  • note that only one colorbar/colormap per axis is allowed (also if you use scatter with colormap/colorbar).
  • plt.colorbar() or fig.colorbar() are also supported (with limited kwargs), and create instance of Colorbar().

TikzConfig

For plot configurations (default sizes, paddings, etc.), use from tikzplot import TikzConfig:

  • modifyParam(PARAM=value) (for runtime session setting),
  • setPermanent(PARAM=value) (for user defined default value). Currently supported parameters are listed with their default values in src/tikzplot/config.py.

More features coming soon...

  • additional arguments support for implemented commands,
  • improved 3D and polar plots,
  • ...

Metadata

Release files for tikzplot42 0.6.2

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

Source distribution (sdist)

Source distribution for tikzplot42 0.6.2
File Size Uploaded Provenance Actions
tikzplot42-0.6.2.tar.gz 174.6 kB Without provenance Details for tikzplot42-0.6.2.tar.gz

Built distribution (wheel)

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

Total release size: 330.5 kB

Release files / tikzplot42-0.6.2.tar.gz

Download URL tikzplot42-0.6.2.tar.gz
Size 174.6 kB
Tags Source
SHA-256 checksum
How to use checksums
10ac941fe513578d6f1033f7b4474a9e6380fd3bbdd51fb4c58447d44d62c7fd
BLAKE2b-256 checksum
How to use checksums
d2f084e14fe09667418a401a4d4da2ba3b21ed482ada978e89a03c125710e790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / tikzplot42-0.6.2-py3-none-any.whl

Download URL tikzplot42-0.6.2-py3-none-any.whl
Size 155.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2afb835a5a9ecb85b6e8a7f84712864e700b0b4693731d3ac6a248763eb4bd4
BLAKE2b-256 checksum
How to use checksums
b95a05f609632af239a01390760a1c5e0d3e6d6cba427d1d5256d73392082e19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for tikzplot42 0.6.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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