python matplotlib绘制图例 报错legend does not support []

在一张图里绘制不同的曲线并显示图例

源代码:

import numpy as np
import matplotlib.pyplot as plt
a=np.loadtxt("1_32.txt")
b=np.loadtxt("1_64.txt")
c=np.loadtxt("1_128.txt")
x=[]
for i in range(200):
    x.append(i+1)
x=np.array(x)
l1=plt.plot(x,a,color="red",label=32)
l2=plt.plot(x,b,color="green",label=64)
l3=plt.plot(x,c,color="blue",label=128)
plt.legend([l1,l2,l3],["32","64","128"],loc=4)
plt.show()

报错

UserWarning: Legend does not support [] instances.
A proxy artist may be used instead.

修改:

l1,=plt.plot(x,a,color="red",label=32)
l2,=plt.plot(x,b,color="green",label=64)
l3,=plt.plot(x,c,color="blue",label=128)

就加了个逗号 其他地方不变
现在图例就可以正常显示了
python matplotlib绘制图例 报错legend does not support []_第1张图片

你可能感兴趣的:(python matplotlib绘制图例 报错legend does not support [])