使用单绘图调用时,将图例添加到 pyplot
add legend to pyplot, when using single plot call
我在绘制多行时习惯了这种语法:
plt.plot(freqs,ps,freqs,psf)
我在其中尝试了label=["ps","psf"]
的不同变体,使用了不同类型的括号,但我总是无法获得正确的图例
plt.plot
将 return 行的句柄列表。您可以将它们与标签列表一起传递给 legend
:
handles=plt.plot([0,1],[5,6],[0,1],[8,7])
plt.legend(handles,["label a","label b"])
我在绘制多行时习惯了这种语法:
plt.plot(freqs,ps,freqs,psf)
我在其中尝试了label=["ps","psf"]
的不同变体,使用了不同类型的括号,但我总是无法获得正确的图例
plt.plot
将 return 行的句柄列表。您可以将它们与标签列表一起传递给 legend
:
handles=plt.plot([0,1],[5,6],[0,1],[8,7])
plt.legend(handles,["label a","label b"])