如何使用 matplotlib 绘制与比例无关的箭头 [英] How to draw scale-independent arrows with matplotlib

查看:43
本文介绍了如何使用 matplotlib 绘制与比例无关的箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 python 中使用 matplotlib 绘制了一个轨迹图,如下所示:

I have drawn a trajectory plot in python using matplotlib of a boat like so:

现在我想添加一些箭头,如风向、真实航向等.但是我希望无论绘图处于哪个缩放级别,箭头都具有相同的大小.我试过 matplotlib.pyplot.arrow,但是我必须定义箭头的长度.我可以让 matplotlib.pyplot.arrow 工作,但是我必须得到图的高度和宽度,并相应地缩放我的箭头,所以我想知道是否有更好的方法来获得这些点的与比例无关的箭头?

Now I want to add some arrows, like wind direction, true heading etc. However I want the arrows to have the same size no matter which zoom-level the plot is at. I tried matplotlib.pyplot.arrow, however there I have to define the length of the arrows. I could make matplotlib.pyplot.arrow work, but then I'd have to get the height and width of the plot, and scale my arrows accordingly, so I wondered if there was a better way to obtain scale-independent arrows for these points?

推荐答案

您想改用 matplotlib.axes.Axes.annotate.请参阅文档 了解更多信息!

You want to use matplotlib.axes.Axes.annotate instead. See the docs for more info!

基本上,将 xycoords 参数设置为 "axes fraction" 以指示它使用轴本身的相对分数而不是数据坐标进行绘图.

Basically, set the xycoords parameter to "axes fraction" to instruct it to plot using relative fraction of the axes itself rather than data coordinates.

这篇关于如何使用 matplotlib 绘制与比例无关的箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆