Python使用方向箭头绘制浮动列表



在matplotlib中用箭头绘制Line plot中的这个答案启发我之后,我尝试了一下,但没有成功。

我的代码:

x = [34.9, 34.9, 34.9, 34.9, 35.7, 34.9, 34.9, 34.1, 34.1, 34.9]
y = [19.544, 19.544, 16.752, 17.45, 17.85, 17.45, 18.846, 17.05, 15.686, 18.846] 
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()

当前输出:

TypeError: unsupported operand type(s) for -: 'list' and 'list'
<Figure size 432x288 with 0 Axes>

您不能使用常用列表。这将工作

x = np.array([34.9, 34.9, 34.9, 34.9, 35.7, 34.9, 34.9, 34.1, 34.1, 34.9])
y = np.array([19.544, 19.544, 16.752, 17.45, 17.85, 17.45, 18.846, 17.05, 15.686, 18.846])
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()

最新更新