编程语言
首页 > 编程语言> > Python:matplotlib UserWarning: Legend does not support ... A proxy artist may be used instead.

Python:matplotlib UserWarning: Legend does not support ... A proxy artist may be used instead.

作者:互联网

在使用 matplotlib.pyplot 画图添加图例:

fig, ax1 = plt.subplots()
line1 = ax1.plot(x, y, color='firebrick')  # draw a line
ax2.legend([line1], ['First'])

显示以下提示:

原因在于,plot 返回 的 list 对象(list of Line2D)需要解构,因此需要在line1和等号之间加一个逗号:

fig, ax1 = plt.subplots()
line1, = ax1.plot(x, y, color='firebrick')  # draw a line
ax2.legend([line1], ['First'])

 

标签:...,used,plot,color,firebrick,artist,list,line1,ax1
来源: https://blog.csdn.net/xiaoxiao_ziteng/article/details/115277094