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 lineax2.legend([line1], ['First']) 

错误信息

显示以下提示:


错误信息

原因与解决方案

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

fig, ax1 = plt.subplots()line1, = ax1.plot(x, y, color='firebrick')  # draw a lineax2.legend([line1], ['First'])
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容