UserWarning: Legend does not support——python matplotlib报错

报错:

UserWarning: Legend does not support [<matplotlib.lines.Line2D object
at 0x00000195927E36C8>] instances. A proxy artist may be used instead.

绘图部分代码

l_a = plt.plot(x, y_weight, color='red', linestyle="--", linewidth=2)  # 在当前绘图对象绘图
l_b = plt.plot(x, y_money, color='blue', linestyle="-.", linewidth=3)

plt.legend(handles=[l_a, l_b], labels=['我不知道', '我也不知道'], prop=my_font)

需要更改代码为
添加上逗号!! 添加的逗号用于解码

l_a, = plt.plot(x, y_weight, color='red', linestyle="--", linewidth=2)  # 在当前绘图对象绘图
l_b, = plt.plot(x, y_money, color='blue', linestyle="-.", linewidth=3)

猜你喜欢

转载自blog.csdn.net/weixin_39589455/article/details/134403056