numpy annotate with three arrows

Solutions on MaxInterview for numpy annotate with three arrows by the best coders in the world

showing results for - "numpy annotate with three arrows"
Julia
06 Apr 2018
1def my_annotate(ax, s, xy_arr=[], *args, **kwargs):
2  ans = []
3  an = ax.annotate(s, xy_arr[0], *args, **kwargs)
4  ans.append(an)
5  d = {}
6  try:
7    d['xycoords'] = kwargs['xycoords']
8  except KeyError:
9    pass
10  try:
11    d['arrowprops'] = kwargs['arrowprops']
12  except KeyError:
13    pass
14  for xy in xy_arr[1:]:
15    an = ax.annotate(s, xy, alpha=0.0, xytext=(0,0), textcoords=an, **d)
16    ans.append(an)
17  return ans
18
19ax = plt.gca()
20ax.plot([1,2,3,4],[1,4,2,6])
21my_annotate(ax,
22            'Test',
23            xy_arr=[(2,4), (3,2), (4,6)], xycoords='data',
24            xytext=(30, -80), textcoords='offset points',
25            bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3),
26            arrowprops=dict(arrowstyle="-|>",
27                            connectionstyle="arc3,rad=0.2",
28                            fc="w"))
29plt.show()