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

Skip to content

Commit 5fde65a

Browse files
committed
AnchoredDirectionArrows: Add demo
1 parent 23f7d5b commit 5fde65a

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDirectionArrows
4+
import matplotlib.font_manager as fm
5+
6+
fig, ax = plt.subplots()
7+
ax.imshow(np.random.random((10,10)))
8+
9+
# Simple example
10+
simple_arrow = AnchoredDirectionArrows(ax.transAxes, 'X','Y')
11+
ax.add_artist(simple_arrow)
12+
13+
# High contrast arrow
14+
high_contrast_part_1 = AnchoredDirectionArrows(
15+
ax.transAxes,
16+
'111', r'11$\overline{2}$',
17+
loc=1,
18+
arrow_props={'ec':'w','fc':'none','alpha':1,'lw':2}
19+
)
20+
ax.add_artist(high_contrast_part_1)
21+
22+
high_contrast_part_2 = AnchoredDirectionArrows(
23+
ax.transAxes,
24+
'111', r'11$\overline{2}$',
25+
loc=1,
26+
arrow_props={'ec':'none','fc':'k'},
27+
text_props={'ec':'w','fc':'k','lw':0.4}
28+
)
29+
ax.add_artist(high_contrast_part_2)
30+
31+
# Rotated arrow
32+
fontprops = fm.FontProperties(family='serif')
33+
34+
roatated_arrow = AnchoredDirectionArrows(
35+
ax.transAxes,
36+
'30', '120',
37+
loc='center',
38+
color='w',
39+
angle=30,
40+
fontproperties=fontprops
41+
)
42+
ax.add_artist(roatated_arrow)
43+
44+
# Altering arrow directions
45+
a1 = AnchoredDirectionArrows(
46+
ax.transAxes, 'A', 'B', loc='lower center',
47+
length=-0.15,
48+
sep_x=0.03, sep_y=0.03,
49+
color = 'r'
50+
)
51+
ax.add_artist(a1)
52+
53+
a2 = AnchoredDirectionArrows(
54+
ax.transAxes, 'A', ' B', loc='lower left',
55+
aspect_ratio=-1,
56+
sep_x=0.01, sep_y=-0.02,
57+
color='orange'
58+
)
59+
ax.add_artist(a2)
60+
61+
62+
a3 = AnchoredDirectionArrows(
63+
ax.transAxes, ' A', 'B', loc='lower right',
64+
length=-0.15,
65+
aspect_ratio=-1,
66+
sep_y=-0.1, sep_x=0.04,
67+
color='cyan'
68+
)
69+
ax.add_artist(a3)
70+
71+
plt.show()

0 commit comments

Comments
 (0)