问题
I have drawn a trajectory plot in python using matplotlib of a boat like so:
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?
回答1:
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.
来源:https://stackoverflow.com/questions/57221054/how-to-draw-scale-independent-arrows-with-matplotlib