Skip to content

max-models/tikzpics

Repository files navigation

Tikzpics

Python interface to generate (readable) Tikz figures.

Install

Create and activate python environment, then install tikzpics with

pip install tikzpics

Examples

Generate tikz-figures with Python API

Generate two nodes connected by an arrow, see Figure 1.

from tikzpics import TikzFigure

fig = TikzFigure()

n1 = fig.add_node(0, 0, shape="circle", color="white", fill="blue", content="Tikz")
n2 = fig.add_node(2, 0, shape="circle", color="white", fill="red", content="Pics")

fig.draw([n1, n2], options=["->", "line width=2"], color="gray")

fig.show()

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

print(fig)
% --------------------------------------------- %
% Tikzfigure generated by tikzpics v0.1.3       %
% https://github.com/max-models/tikzpics        %
% --------------------------------------------- %
\begin{tikzpicture}
    \node[shape=circle, color=white, fill=blue] (node0) at (0, 0) {Tikz};
    \node[shape=circle, color=white, fill=red] (node1) at (2, 0) {Pics};
    \draw[->, line width=2, color=gray] (node0) to (node1);
\end{tikzpicture}

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

IPython Magic Commands

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

Load the extension:

%load_ext tikzpics.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!

About

Python interface to generate (readable) Tikz figures

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors