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'])

显示以下提示:

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

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

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

 

上一篇:3D Modeling for Unity: The Complete Guide


下一篇:中文 APB Artist Sessions Presents- SHAUN BARRETT