How to get arrowhead tip for start / end with given coordinates in Python?

I am trying to build lines with arrowheads at both ends using the matplotlib annotation. But when I draw them, the arrowhead tips do not start and end at the specified coordinates, as shown in the figure. Tips should begin and end at 0.6 and 0.8, but they do not.

enter image description here

Playable code

import matplotlib.pyplot as plt fig = plt.figure(figsize = (5, 5)) plt = plt.subplot(111) plt.axvline(0.6) plt.axvline(0.8) plt.axhline(0.6) plt.axhline(0.8) plt.annotate('', xy = (0.6, 0.33), xycoords = 'axes fraction', \ xytext = (0.8, 0.33), textcoords = 'axes fraction', fontsize = 7, \ color = '#303030', arrowprops=dict(edgecolor='black', arrowstyle = '<->')) plt.annotate('', xy = (0.33, 0.6), xycoords = 'axes fraction', \ xytext = (0.33, 0.8), textcoords = 'axes fraction', fontsize = 7, \ color = '#303030', arrowprops=dict(edgecolor='black', arrowstyle = '<->')) fig.savefig('arrow_head.pdf') 

Why is this happening? And how to get tips for starting or ending in the appropriate coordinates?

+5
source share
1 answer

According to the documentation here , the path is shortened according to the parameters specified in shrinkA and shrinkB , presumably to provide a small distance when the arrow points to something. The default value is 2, so if you set the value to 0, the distance should disappear. For instance:

 plt.annotate('', xy = (0.6, 0.33), xycoords = 'axes fraction', \ xytext = (0.8, 0.33), textcoords = 'axes fraction', fontsize = 7, \ color = '#303030', arrowprops=dict(edgecolor='black', arrowstyle = '<->', shrinkA = 0, shrinkB = 0)) 

Graph with lines and arrows.

+9
source

All Articles