简体   繁体   English

在matplotlib中带箭头的线图

[英]Line plot with arrows in matplotlib

I have a line graph that I want to plot using arrows instead 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. 我知道arrow功能,但似乎只做单独的箭头。 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. 你可以用quiver做到这一点,但是让关键字参数正确是有点棘手的。

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()

在此输入图像描述

您可以在线图上叠加箭袋图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM