-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[ENH]: Improve plt.arrow default head shape #22379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The function should actually be the following: def norm_arrow(ax, x1, y1, x2, y2, head_scale=0.1, head_width=None, **kwargs):
dx,dy = x2-x1,y2-y1
norm = np.sqrt(dx*dx + dy*dy)
l = head_scale*norm
w = head_width if head_width is not None else 0.5*l
ax.arrow(x1, y1, dx, dy, head_width=w, head_length=l, length_includes_head=True, **kwargs) The original version only works for arrows that start at the origin (oops). |
Plt.arrow is definitely broken and we have considered deprecating it. But scaling arrow heads by the length of the arrow does not strike me as a very good solution either. For one arrow it looks good, but different length arrows will have different arrow heads. Also non-equal aspect ratio axes will have different head sizes depending on if the arrow points in one direction or the other. Rather the arrowhead should dimensioned and drawn in physical units, which I am pretty sure is what happens with plt.annotate. |
Crossref #20387 for discussion of deprecating |
See #22382 for the purposed deprecation... |
I concur that
|
closing in favor of #22390 |
Problem
The default for the head width/length of the fancy arrow patch are not very good. See for example: https://philbull.wordpress.com/2012/04/05/drawing-arrows-in-matplotlib/
This means that in order to get a usable arrow you need to mess around with options such as
head_length
which can be tricky to learn about.Proposed solution
Use a new heuristic for head sizing as a default behavior.
@kmdalton suggested the below function
norm_arrow
which you can see gives better defaults in two basic test cases.The text was updated successfully, but these errors were encountered: