Python matplotlib画图出现No handles with labels found to put in legend

1、在使用Python matplotlib画图出现No handles with labels found to put in legend ,在本地调试时并不会出现这个错误,而部署到线上服务器之后,便出现这种错误。

2、报错代码为下面一行:

plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.03), fancybox=True, ncol=5)

3、原因,使用matplotlib展示图例的时候呢,没有设置多一个参数labels的原因,因此修改上面代码为:

plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.03), fancybox=True, ncol=5, labels=['年龄', '性别'])

4、如果只需要一个图例,labels="年龄"这样即可,之后就不会出现这个问题了。

 
发布了276 篇原创文章 · 获赞 200 · 访问量 72万+

猜你喜欢

转载自blog.csdn.net/u012561176/article/details/90297601