Skip to content

Commit 76ef4b9

Browse files
committed
add arrow test
1 parent 3090414 commit 76ef4b9

File tree

2 files changed

+258
-0
lines changed

2 files changed

+258
-0
lines changed

test/test_arrows.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
import matplotlib.patches as mpatches
4+
import matplotlib.pyplot as plt
5+
6+
7+
# https://matplotlib.org/examples/pylab_examples/fancyarrow_demo.html
8+
def plot():
9+
styles = mpatches.ArrowStyle.get_styles()
10+
11+
ncol = 2
12+
nrow = (len(styles) + 1) // ncol
13+
figheight = nrow + 0.5
14+
fig1 = plt.figure(1, (4.0 * ncol / 1.5, figheight / 1.5))
15+
fontsize = 0.2 * 70
16+
17+
ax = fig1.add_axes([0, 0, 1, 1], frameon=False, aspect=1.0)
18+
19+
ax.set_xlim(0, 4 * ncol)
20+
ax.set_ylim(0, figheight)
21+
22+
def to_texstring(s):
23+
s = s.replace("<", r"$<$")
24+
s = s.replace(">", r"$>$")
25+
s = s.replace("|", r"$|$")
26+
return s
27+
28+
for i, (stylename, styleclass) in enumerate(sorted(styles.items())):
29+
x = 3.2 + (i // nrow) * 4
30+
y = figheight - 0.7 - i % nrow # /figheight
31+
p = mpatches.Circle((x, y), 0.2)
32+
ax.add_patch(p)
33+
34+
ax.annotate(
35+
to_texstring(stylename),
36+
(x, y),
37+
(x - 1.2, y),
38+
# xycoords="figure fraction", textcoords="figure fraction",
39+
ha="right",
40+
va="center",
41+
size=fontsize,
42+
arrowprops=dict(
43+
arrowstyle=stylename,
44+
patchB=p,
45+
shrinkA=5,
46+
shrinkB=5,
47+
fc="k",
48+
ec="k",
49+
connectionstyle="arc3,rad=-0.05",
50+
),
51+
bbox=dict(boxstyle="square", fc="w"),
52+
)
53+
54+
ax.xaxis.set_visible(False)
55+
ax.yaxis.set_visible(False)
56+
return plt.gcf()
57+
58+
59+
# if __name__ == "__main__":
60+
# import helpers
61+
#
62+
# # fig = plot()
63+
# # helpers.print_tree(fig)
64+
# # plt.show()
65+
#
66+
# plot()
67+
# import matplotlib2tikz
68+
# code = matplotlib2tikz.get_tikz_code(include_disclaimer=False, standalone=True)
69+
# plt.close()
70+
# helpers._does_compile(code)
71+
72+
if __name__ == "__main__":
73+
import helpers
74+
helpers.compare_mpl_latex(plot)
75+
# helpers.print_tree(plot())

test/test_arrows_reference.tex

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
\begin{tikzpicture}
2+
3+
\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
4+
5+
\begin{axis}[
6+
tick align=outside,
7+
tick pos=left,
8+
x grid style={white!69.01960784313725!black},
9+
xmin=0, xmax=8,
10+
y grid style={white!69.01960784313725!black},
11+
ymin=0, ymax=7.5
12+
]
13+
\draw[fill=color0,draw opacity=0] (axis cs:3.2,6.8) circle (0.2);
14+
\draw[fill=color0,draw opacity=0] (axis cs:3.2,5.8) circle (0.2);
15+
\draw[fill=color0,draw opacity=0] (axis cs:3.2,4.8) circle (0.2);
16+
\draw[fill=color0,draw opacity=0] (axis cs:3.2,3.8) circle (0.2);
17+
\draw[fill=color0,draw opacity=0] (axis cs:3.2,2.8) circle (0.2);
18+
\draw[fill=color0,draw opacity=0] (axis cs:3.2,1.8) circle (0.2);
19+
\draw[fill=color0,draw opacity=0] (axis cs:3.2,0.8) circle (0.2);
20+
\draw[fill=color0,draw opacity=0] (axis cs:7.2,6.8) circle (0.2);
21+
\draw[fill=color0,draw opacity=0] (axis cs:7.2,5.8) circle (0.2);
22+
\draw[fill=color0,draw opacity=0] (axis cs:7.2,4.8) circle (0.2);
23+
\draw[fill=color0,draw opacity=0] (axis cs:7.2,3.8) circle (0.2);
24+
\draw[fill=color0,draw opacity=0] (axis cs:7.2,2.8) circle (0.2);
25+
\draw[fill=color0,draw opacity=0] (axis cs:7.2,1.8) circle (0.2);
26+
\draw[fill=color0,draw opacity=0] (axis cs:7.2,0.8) circle (0.2);
27+
\draw[-,black] (axis cs:2,6.8) -- (axis cs:3.2,6.8);
28+
\node at (axis cs:2,6.8)[
29+
scale=0.7,
30+
fill=white,
31+
draw=black,
32+
line width=0.4pt,
33+
inner sep=3pt,
34+
anchor= east,
35+
text=black,
36+
rotate=0.0
37+
]{ -};
38+
\draw[->,black] (axis cs:2,5.8) -- (axis cs:3.2,5.8);
39+
\node at (axis cs:2,5.8)[
40+
scale=0.7,
41+
fill=white,
42+
draw=black,
43+
line width=0.4pt,
44+
inner sep=3pt,
45+
anchor= east,
46+
text=black,
47+
rotate=0.0
48+
]{ -$>$};
49+
\draw[-|,black] (axis cs:2,4.8) -- (axis cs:3.2,4.8);
50+
\node at (axis cs:2,4.8)[
51+
scale=0.7,
52+
fill=white,
53+
draw=black,
54+
line width=0.4pt,
55+
inner sep=3pt,
56+
anchor= east,
57+
text=black,
58+
rotate=0.0
59+
]{ -[};
60+
\draw[-latex,black] (axis cs:2,3.8) -- (axis cs:3.2,3.8);
61+
\node at (axis cs:2,3.8)[
62+
scale=0.7,
63+
fill=white,
64+
draw=black,
65+
line width=0.4pt,
66+
inner sep=3pt,
67+
anchor= east,
68+
text=black,
69+
rotate=0.0
70+
]{ -$|$$>$};
71+
\draw[<-,black] (axis cs:2,2.8) -- (axis cs:3.2,2.8);
72+
\node at (axis cs:2,2.8)[
73+
scale=0.7,
74+
fill=white,
75+
draw=black,
76+
line width=0.4pt,
77+
inner sep=3pt,
78+
anchor= east,
79+
text=black,
80+
rotate=0.0
81+
]{ $<$-};
82+
\draw[<->,black] (axis cs:2,1.8) -- (axis cs:3.2,1.8);
83+
\node at (axis cs:2,1.8)[
84+
scale=0.7,
85+
fill=white,
86+
draw=black,
87+
line width=0.4pt,
88+
inner sep=3pt,
89+
anchor= east,
90+
text=black,
91+
rotate=0.0
92+
]{ $<$-$>$};
93+
\draw[latex-,black] (axis cs:2,0.8) -- (axis cs:3.2,0.8);
94+
\node at (axis cs:2,0.8)[
95+
scale=0.7,
96+
fill=white,
97+
draw=black,
98+
line width=0.4pt,
99+
inner sep=3pt,
100+
anchor= east,
101+
text=black,
102+
rotate=0.0
103+
]{ $<$$|$-};
104+
\draw[latex-latex,black] (axis cs:6,6.8) -- (axis cs:7.2,6.8);
105+
\node at (axis cs:6,6.8)[
106+
scale=0.7,
107+
fill=white,
108+
draw=black,
109+
line width=0.4pt,
110+
inner sep=3pt,
111+
anchor= east,
112+
text=black,
113+
rotate=0.0
114+
]{ $<$$|$-$|$$>$};
115+
\draw[|-,black] (axis cs:6,5.8) -- (axis cs:7.2,5.8);
116+
\node at (axis cs:6,5.8)[
117+
scale=0.7,
118+
fill=white,
119+
draw=black,
120+
line width=0.4pt,
121+
inner sep=3pt,
122+
anchor= east,
123+
text=black,
124+
rotate=0.0
125+
]{ ]-};
126+
\draw[|-|,black] (axis cs:6,4.8) -- (axis cs:7.2,4.8);
127+
\node at (axis cs:6,4.8)[
128+
scale=0.7,
129+
fill=white,
130+
draw=black,
131+
line width=0.4pt,
132+
inner sep=3pt,
133+
anchor= east,
134+
text=black,
135+
rotate=0.0
136+
]{ ]-[};
137+
\draw[-latex,very thick,black] (axis cs:6,3.8) -- (axis cs:7.2,3.8);
138+
\node at (axis cs:6,3.8)[
139+
scale=0.7,
140+
fill=white,
141+
draw=black,
142+
line width=0.4pt,
143+
inner sep=3pt,
144+
anchor= east,
145+
text=black,
146+
rotate=0.0
147+
]{ fancy};
148+
\draw[-latex,very thick,black] (axis cs:6,2.8) -- (axis cs:7.2,2.8);
149+
\node at (axis cs:6,2.8)[
150+
scale=0.7,
151+
fill=white,
152+
draw=black,
153+
line width=0.4pt,
154+
inner sep=3pt,
155+
anchor= east,
156+
text=black,
157+
rotate=0.0
158+
]{ simple};
159+
\draw[-latex,very thick,black] (axis cs:6,1.8) -- (axis cs:7.2,1.8);
160+
\node at (axis cs:6,1.8)[
161+
scale=0.7,
162+
fill=white,
163+
draw=black,
164+
line width=0.4pt,
165+
inner sep=3pt,
166+
anchor= east,
167+
text=black,
168+
rotate=0.0
169+
]{ wedge};
170+
\draw[|-|,black] (axis cs:6,0.8) -- (axis cs:7.2,0.8);
171+
\node at (axis cs:6,0.8)[
172+
scale=0.7,
173+
fill=white,
174+
draw=black,
175+
line width=0.4pt,
176+
inner sep=3pt,
177+
anchor= east,
178+
text=black,
179+
rotate=0.0
180+
]{ $|$-$|$};
181+
\end{axis}
182+
183+
\end{tikzpicture}

0 commit comments

Comments
 (0)