import
matplotlib.pyplot as plt
import
numpy as np
import
matplotlib.path as mpath
import
matplotlib.lines as mlines
import
matplotlib.patches as mpatches
from
matplotlib.collections
import
PatchCollection
def
label(xy, text):
y
=
xy[
1
]
-
0.15
plt.text(xy[
0
], y, text, ha
=
"center"
,
family
=
'sans-serif'
, size
=
14
)
fig, ax
=
plt.subplots()
grid
=
np.mgrid[
0.2
:
0.8
:
3j
,
0.2
:
0.8
:
3j
].reshape(
2
,
-
1
).T
patches
=
[]
arrow
=
mpatches.Arrow(grid[
5
,
0
]
-
0.05
,
grid[
5
,
1
]
-
0.05
,
0.1
,
0.1
,
width
=
0.1
)
patches.append(arrow)
label(grid[
5
],
" Sample Arrow"
)
colors
=
np.linspace(
0
,
1
,
len
(patches))
collection
=
PatchCollection(patches,
cmap
=
plt.cm.hsv,
alpha
=
0.3
)
collection.set_array(np.array(colors))
ax.add_collection(collection)
plt.axis(
'equal'
)
plt.axis(
'off'
)
plt.tight_layout()
plt.show()