matplotlib 中带箭头的线图 [英] Line plot with arrows in matplotlib

查看:56
本文介绍了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.

我知道 arrow 函数,但这似乎只能用于单个箭头.在我想出一种方法来尝试使用它来完成整个情节之前,有没有更好的方法来做到这一点?

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?

推荐答案

你可以用 quiver,但正确使用关键字参数有点棘手.

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

这篇关于matplotlib 中带箭头的线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆