我正在尝试在PyPlot中创建一个平行四边形。首先,我要使用以下代码插入矢量箭头,而不是绘制平行四边形:
fig = plt.figure()
ax = fig.add_subplot(111)
ax.spines['left'].set_position('zero')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
plt.axis([-5,5,-5,5])
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
plt.grid()
plt.arrow(0,0, 3,1, head_width=0.2, color='r', length_includes_head=True, label='u')
plt.arrow(0,0, 1,3, head_width=0.2, color='r', length_includes_head=True, label='v')
plt.arrow(0,0, 4,4, head_width=0.2, color='r', length_includes_head=True, label='u+v')
plt.legend()
这会返回以下错误:
No handles with labels found to put in legend.
我不确定为什么,因为根据plt.arrow()
的文档,label
是一个可接受的关键字参数,plt.legend()
应该可以读取它。图的其余部分绘制得很好;只是缺少图例。