Skip to main content

Python interface to generate (readable) Tikz figures.

Project description

tikzfigure

Python interface to generate (readable) Tikz figures.

Install

Create and activate python environment, then install tikzfigure with

pip install tikzfigure

Examples

Generate tikz-figures with Python API

Generate a simple TikZ figure with nodes and arrows, see Figure 1.

from tikzfigure import TikzFigure

fig = TikzFigure()

n1 = fig.node(x=0, y=0, shape="circle", fill="blue!40!green", content="Tikz")
n2 = fig.node(x=2, y=0, shape="circle", fill="purple!40!orange", content="Figure")

fig.draw([n1, n2], line_width=2, arrows="->", color="gray")

fig.variable("R", 1.0)

with fig.loop("angle", range(40, 340, 20)) as loop:
    loop.node(
        x=r"\R*cos(\angle)",
        y=r"\R*sin(\angle)",
        shape="circle",
        fill="red!50",
    )

fig.show()

For segment-local TikZ options, you can also build paths fluently with Node.to(...) and keep path-wide styling on fig.draw(...).

You can also save the figure as a .tikz file or print the LaTeX code:

print(fig)
% --------------------------------------------- %
% Tikzfigure generated by tikzfigure v0.2.1     %
% https://github.com/max-models/tikzfigure      %
% --------------------------------------------- %
\begin{tikzpicture}
    \pgfmathsetmacro{\R}{1.0}
    \node[shape=circle, fill=blue!40!green] (node0) at ({0}, {0}) {Tikz};
    \node[shape=circle, fill=purple!40!orange] (node1) at ({2}, {0}) {Figure};
    \draw[color=gray, line width=2, arrows=->] (node0) to (node1);
    \foreach \angle in {40,60,80,100,120,140,160,180,200,220,240,260,280,300,320}{
        \node[shape=circle, fill=red!50] () at ({\R*cos(\angle)}, {\R*sin(\angle)}) {};
    }
\end{tikzpicture}

Note that to visualize the plots in a popup or in jupyterlab, install with pip install "tikzfigure[vis]"

IPython Magic Commands

tikzfigure includes IPython magic commands for compiling TikZ figures directly in Jupyter notebooks!

Load the extension:

%load_ext tikzfigure.ipython

Then use the %%tikz cell magic:

%%tikz
\begin{tikzpicture}
\draw[thick, blue] (0,0) circle (2cm);
\node at (0,0) {Hello TikZ!};
\end{tikzpicture}

See tutorials for more examples!

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

tikzfigure-0.3.0.tar.gz (132.1 kB view details)

Uploaded Source

Built Distribution

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

tikzfigure-0.3.0-py3-none-any.whl (163.3 kB view details)

Uploaded Python 3

File details

Details for the file tikzfigure-0.3.0.tar.gz.

File metadata

  • Download URL: tikzfigure-0.3.0.tar.gz
  • Upload date:
  • Size: 132.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tikzfigure-0.3.0.tar.gz
Algorithm Hash digest
SHA256 97a3755fe71c4d09864ea26b297d370d62a8960638dec7aaedc84c67d163bcc3
MD5 b60c5e070dd911c7c9710dd4cf7c9c81
BLAKE2b-256 63b6241ceff988b0b1eebadbf409564bea8c9bc700a5830057b3c92b42c037ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for tikzfigure-0.3.0.tar.gz:

Publisher: publish_pypi.yml on max-models/tikzfigure

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

File details

Details for the file tikzfigure-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: tikzfigure-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 163.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tikzfigure-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0de8698f4e108cb4e10527d8560158709fb8c35ac8ffa5e3c9a070774813b632
MD5 c876e5589f702874e1589889d6ce9998
BLAKE2b-256 9c01fc9d34e5ff0e8075c15d097e808e52904f5a259567af0f5380ad05e08cdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for tikzfigure-0.3.0-py3-none-any.whl:

Publisher: publish_pypi.yml on max-models/tikzfigure

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