图例未在matplotlib中正确显示

798qvoo8  于 2023-02-13  发布在  其他
关注(0)|答案(1)|浏览(90)

Rs= [20, 20, 20, 20]
Ls = [20, 30, 40, 50]
times = [t/10.0 for t in range(0,100)]
for R, L in zip(Rs, Ls):
    I = [m.exp((-R/L)*t)-1 for t in times]
    plt.plot(times,I)
    plt.legend(str(L))

我希望得到20,30,40和50的图例,但是5和0出现了。我的代码出了什么问题?

xytpbqjk

xytpbqjk1#

使用plot()label参数,并在循环外部调用legend()

for R, L in zip(Rs, Ls):
    I = [m.exp((-R/L)*t)-1 for t in times]
    plt.plot(times, I, label=str(L))

plt.legend()

输出:

相关问题