Tutorial 4
[1]:
"""
Tutorial 4.
Add raw tikz code to the tikz subplot.
"""
[1]:
'\nTutorial 4.\n\nAdd raw tikz code to the tikz subplot.\n'
[2]:
from maxplotlib import Canvas
[3]:
c = Canvas(width=800, ratio=0.5)
tikz = c.add_tikzfigure(grid=False)
[4]:
# Add nodes
tikz.add_node(0, 0, label="A", shape="circle", draw="black", fill="blue", layer=0)
tikz.add_node(10, 0, label="B", shape="circle", draw="black", fill="blue", layer=0)
tikz.add_node(10, 10, label="C", shape="circle", draw="black", fill="blue", layer=0)
tikz.add_node(0, 10, label="D", shape="circle", draw="black", fill="blue", layer=2)
[4]:
<tikzpics.node.Node at 0x10ce7b5c0>
[5]:
# Add a line between nodes
tikz.draw(
["A", "B", "C", "D"],
path_actions=["draw", "rounded corners"],
fill="red",
opacity=0.5,
cycle=True,
layer=1,
)
[5]:
<tikzpics.path.Path at 0x113e4d940>
[6]:
raw_tikz = r"""
\foreach \i in {0, 45, 90, 135, 180, 225, 270, 315} {
% Place a node at angle \i
\node[circle, draw, fill=green] at (\i:3) (N\i) {};
}
% Draw lines connecting the nodes
\foreach \i/\j in {0/45, 45/90, 90/135, 135/180, 180/225, 225/270, 270/315, 315/0} {
\draw (N\i) -- (N\j);
}
"""
[8]:
# TODO: Not implemented in tikzpics yet
# tikz.add_raw(raw_tikz)
[9]:
tikz.add_node(0.5, 0.5, content="Cube", layer=10)
[9]:
<tikzpics.node.Node at 0x113ecba80>
[ ]:
# Generate the TikZ script
script = tikz.generate_tikz()
print(script)
% --------------------------------------------- %
% Tikzfigure generated by tikzpics v0.1.1 %
% https://github.com/max-models/tikzpics %
% --------------------------------------------- %
\begin{tikzpicture}
% Define the layers library
\pgfdeclarelayer{0}
\pgfdeclarelayer{1}
\pgfdeclarelayer{10}
\pgfdeclarelayer{2}
\pgfsetlayers{0,1,10,2}
% Layer 0
\begin{pgfonlayer}{0}
\node[shape=circle, draw=black, fill=blue] (A) at (0, 0) {};
\node[shape=circle, draw=black, fill=blue] (B) at (10, 0) {};
\node[shape=circle, draw=black, fill=blue] (C) at (10, 10) {};
\end{pgfonlayer}{0}
% Layer 2
\begin{pgfonlayer}{2}
\node[shape=circle, draw=black, fill=blue] (D) at (0, 10) {};
\end{pgfonlayer}{2}
% Layer 1
\begin{pgfonlayer}{1}
\draw[path actions=['draw', 'rounded corners'], fill=red, opacity=0.5] (A) to (B) to (C) to (D) -- cycle;
\end{pgfonlayer}{1}
% Layer 10
\begin{pgfonlayer}{10}
\node (node4) at (0.5, 0.5) {Cube};
\end{pgfonlayer}{10}
\end{tikzpicture}