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.

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,
  • \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(),
  • loglog(),
  • semilogx()/semilogy(),
  • errorbar(),
  • stem(),
  • fill_between(),
  • hlines()/vlines(),
  • hist(),
  • bar()/barh(),
  • bar_label(),
  • step(),
  • imshow(),
  • text(),
  • 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).

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(),

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

  • color/c,
  • linestyle/ls,
  • linewidth/ls,
  • fmt,
  • marker,
  • marksize/ms,
  • alpha,
  • label.

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).

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 plots (currently only basic support: plot, errorbar, fill_between, scatter, plot_wireframe, plot_surface),
  • ...

Release files for tikzplot42 0.5.1

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.5.1
File Size Uploaded
tikzplot42-0.5.1.tar.gz 109.8 kB Details

Built distribution (wheel)

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

Total release size: 206.3 kB

Release files / tikzplot42-0.5.1.tar.gz

Download URL tikzplot42-0.5.1.tar.gz
Size 109.8 kB
Tags Source
SHA-256 checksum
How to use checksums
d63af89256c7d38ae712557da8aeba32ac77dbb6c8dbc254316ea09b7072aae0
BLAKE2b-256 checksum
How to use checksums
44bf78f72b4c6189d7b886953168e545bf66d52df0767196b8b0cc783791a65f
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.5.1-py3-none-any.whl

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

Release history Release notifications | RSS feed

0.6.0

2 release files

0.5.14

2 release files

0.5.13

2 release files

0.5.10

2 release files

0.5.8

2 release files

0.5.4

2 release files

0.5.2

2 release files

This release

0.5.1 This release

2 release files

0.5.0

2 release files

0.4.7

2 release files

0.4.3

2 release files

0.3.9

2 release files

0.3.8

2 release files

0.3.7

2 release files

0.3.6

2 release files

0.3.4

2 release files

0.3.0

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