Search code examples
pythonmatplotlibannotationsarrows

How to draw scale-independent arrows with matplotlib


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

enter image description here

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?


Solution

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

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