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

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

问题描述

我已经使用python的matplotlib在python中绘制了一个轨迹图,像这样:

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 参数设置为轴分数 指示它使用轴本身的相对分数而不是数据坐标进行绘制。

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天全站免登陆