Tutorial 2
[1]:
from maxplotlib import Canvas
%load_ext autoreload
%autoreload 2
[2]:
c = Canvas(width=800, ratio=0.5)
tikz = c.add_tikzfigure(grid=False)
# Add nodes
tikz.add_node(0, 0, label="A", shape="circle", draw="black", fill="blue", layer=0)
tikz.add_node(1, 0, label="B", shape="circle", draw="black", fill="blue", layer=0)
tikz.add_node(1, 1, label="C", shape="circle", draw="black", fill="blue", layer=0)
tikz.add_node(0, 1, label="D", shape="circle", draw="black", fill="blue", layer=2)
# Add a line between nodes
tikz.draw(
["A", "B", "C", "D"],
path_actions=["draw", "rounded corners"],
fill="red",
opacity=1.0,
cycle=True,
layer=1,
)
tikz.add_node(0.5, 0.5, content="Cube", layer=10)
# tikz.compile_pdf("tutorial_02_01.pdf")
c.plot(backend="matplotlib")
[2]:
(<Figure size 3320.88x1660.44 with 1 Axes>, array([[<Axes: >]], dtype=object))
Ignoring fixed x limits to fulfill fixed data aspect with adjustable data limits.
[3]:
c = Canvas(width="10cm", ncols=2, ratio=0.5)
tikz = c.add_tikzfigure(grid=False)
# Add nodes
node_a = tikz.add_node(
-5,
0,
label="A",
content="Origin node",
shape="circle",
draw="black",
fill="blue!20",
)
tikz.add_node(
2,
2,
label="B",
content="$a^2 + b^2 = c^2$",
shape="rectangle",
draw="red",
fill="white",
layer=1,
)
tikz.add_node(2, 5, label="C", shape="rectangle", draw="red", fill="red")
last_node = tikz.add_node(-1, 5, shape="rectangle", draw="red", fill="red", layer=-10)
# # Add a line between nodes
tikz.draw(
[node_a.label, "B", "C", "A", last_node],
color="green",
style="solid",
line_width="2",
layer=-5,
)
sp = c.add_subplot(
grid=True, xlabel="(x - 10) * 0.1", ylabel="10y", yscale=10, xshift=-10, xscale=0.1
)
sp.add_line([0, 1, 2, 3], [0, 1, 4, 9], label="Line 1")
sp.add_line([0, 1, 2, 3], [0, 2, 3, 4], linestyle="dashed", color="red", label="Line 2")
# Generate the TikZ script
# print(tikz.generate_standalone())
# tikz.compile_pdf("tutorial_02_02.pdf")
c.plot(backend="matplotlib")
[3]:
(<Figure size 4902.87x2451.44 with 2 Axes>,
array([[<Axes: >, <Axes: xlabel='(x - 10) * 0.1', ylabel='10y'>]],
dtype=object))
Ignoring fixed y limits to fulfill fixed data aspect with adjustable data limits.
[4]:
c = Canvas(width=800, ratio=0.5)
tikz = c.add_tikzfigure(grid=False)
# Add nodes
tikz.add_node(0, 0, label="A")
tikz.add_node(10, 0, label="B")
# Add a line between nodes
tikz.draw(["A", "B"], path_actions=["->"], out=30)
# Generate the TikZ script
# script = tikz.generate_tikz()
# print(script)
print(tikz.generate_standalone())
# tikz.compile_pdf("tutorial_02_03.pdf")
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows.meta}
\begin{document}
% --------------------------------------------- %
% Tikzfigure generated by tikzpics v0.1.1 %
% https://github.com/max-models/tikzpics %
% --------------------------------------------- %
\begin{tikzpicture}
% Define the layers library
\pgfdeclarelayer{0}
\pgfsetlayers{0}
% Layer 0
\begin{pgfonlayer}{0}
\node (A) at (0, 0) {};
\node (B) at (10, 0) {};
\draw[path actions=['->'], out=30] (A) to (B);
\end{pgfonlayer}{0}
\end{tikzpicture}
\end{document}