Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e5706a8

Browse files
committed
First complete version
1 parent 821f05e commit e5706a8

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

cheatsheets.tex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -938,8 +938,17 @@
938938
\API{https://matplotlib.org/tutorials/text/annotations.html} }
939939
\includegraphics[width=\columnwidth]{annotation-connection-styles.pdf}
940940
\end{myboxed}
941-
942-
\vfill\null \columnbreak
941+
%
942+
\vspace{\fill}
943+
%
944+
\begin{myboxed}{Annotation arrow styles \hfill
945+
\API{https://matplotlib.org/tutorials/text/annotations.html} }
946+
\includegraphics[width=\columnwidth]{annotation-arrow-styles.pdf}
947+
\end{myboxed}
948+
949+
%
950+
\vspace{\fill}
951+
%
943952

944953
%
945954
\begin{myboxed}{How do I …}

scripts/annotation-arrow-styles.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import matplotlib.pyplot as plt
2+
import matplotlib.patches as mpatches
3+
4+
styles = mpatches.ArrowStyle.get_styles()
5+
def demo_con_style(ax, connectionstyle):
6+
ax.text(.05, .95, connectionstyle.replace(",", ",\n"),
7+
family="Source Code Pro",
8+
transform=ax.transAxes, ha="left", va="top", size="x-small")
9+
10+
fig, ax = plt.subplots(figsize=(4, 2.5), frameon=False)
11+
ax.axis("off")
12+
for i,style in enumerate(mpatches.ArrowStyle.get_styles()):
13+
x0, y0 = 5 + 5*(i%3), -(i//3)
14+
x1, y1 = 1 + 5*(i%3), -(i//3)
15+
ax.plot([x0, x1], [y0, y1], ".", color="0.25")
16+
ax.annotate("",
17+
xy=(x0, y0), xycoords='data',
18+
xytext=(x1, y1), textcoords='data',
19+
arrowprops=dict(arrowstyle=style,
20+
color="black",
21+
shrinkA=5, shrinkB=5,
22+
patchA=None, patchB=None,
23+
connectionstyle="arc3,rad=0"))
24+
ax.text( (x1+x0)/2, y0-0.2, style,
25+
family = "Source Code Pro", ha="center", va="top")
26+
27+
plt.savefig("../figures/annotation-arrow-styles.pdf")
28+
# plt.show()
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import matplotlib.pyplot as plt
2+
3+
def demo_con_style(ax, connectionstyle):
4+
x1, y1 = 0.3, 0.2
5+
x2, y2 = 0.8, 0.6
6+
ax.plot([x1, x2], [y1, y2], ".")
7+
ax.annotate("",
8+
xy=(x1, y1), xycoords='data',
9+
xytext=(x2, y2), textcoords='data',
10+
arrowprops=dict(arrowstyle="->", color="0.5",
11+
shrinkA=5, shrinkB=5,
12+
patchA=None, patchB=None,
13+
connectionstyle=connectionstyle),
14+
)
15+
ax.text(.05, .95, connectionstyle.replace(",", ",\n"),
16+
family="Source Code Pro",
17+
transform=ax.transAxes, ha="left", va="top", size="x-small")
18+
19+
fig, axs = plt.subplots(3, 3, figsize=(5, 5))
20+
demo_con_style(axs[0, 0], "arc3,rad=0")
21+
demo_con_style(axs[0, 1], "arc3,rad=0.3")
22+
demo_con_style(axs[0, 2], "angle3,angleA=0,angleB=90")
23+
demo_con_style(axs[1, 0], "angle,angleA=-90,angleB=180,rad=0")
24+
demo_con_style(axs[1, 1], "angle,angleA=-90,angleB=180,rad=25")
25+
demo_con_style(axs[1, 2], "arc,angleA=-90,angleB=0,armA=0,armB=40,rad=0")
26+
demo_con_style(axs[2, 0], "bar,fraction=0.3")
27+
demo_con_style(axs[2, 1], "bar,fraction=-0.3")
28+
demo_con_style(axs[2, 2], "bar,angle=180,fraction=-0.2")
29+
30+
for ax in axs.flat:
31+
ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1)
32+
fig.tight_layout(pad=0.2)
33+
34+
plt.savefig("../figures/annotation-connection-styles.pdf")
35+
# plt.show()

0 commit comments

Comments
 (0)