gpt4 book ai didi

python - 使用单图调用时,将图例添加到 pyplot

转载 作者:行者123 更新时间:2023-12-01 04:09:59 26 4
gpt4 key购买 nike

绘制多条线时我习惯了这种语法:

plt.plot(freqs,ps,freqs,psf)

我在其中尝试了 label=["ps","psf"] 的不同变体,使用不同类型的括号,但我总是无法获得正确的图例

最佳答案

plt.plot 将返回线条句柄列表。您可以将它们连同标签列表一起传递给 legend:

handles=plt.plot([0,1],[5,6],[0,1],[8,7])
plt.legend(handles,["label a","label b"])

关于python - 使用单图调用时,将图例添加到 pyplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35081552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com