开发者

Line plot with arrows in matplotlib

开发者 https://www.devze.com 2023-04-06 15:17 出处:网络
I have a line graph that I want to plot using arrows ins开发者_如何学Ctead of lines. That is, the line between successive pairs of points should be an arrow going from the first point to the second po

I have a line graph that I want to plot using arrows ins开发者_如何学Ctead of lines. That is, the line between successive pairs of points should be an arrow going from the first point to the second point.

I know of the arrow function, but that only seems to do individual arrows. Before I work out a way to try and use this to do a whole plot, is there a nicer way to do it?


You can do this with quiver, but it's a little tricky to get the keyword arguments right.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0, 2*np.pi, 10)
y = np.sin(x)

plt.figure()
plt.quiver(x[:-1], y[:-1], x[1:]-x[:-1], y[1:]-y[:-1], scale_units='xy', angles='xy', scale=1)

plt.show()

Line plot with arrows in matplotlib


You could superpose a quiver plot on your line plot.

0

精彩评论

暂无评论...
验证码 换一张
取 消