无法在Seadist发行版中显示图例 [英] Unable to show legend in seaborn distplot

查看:49
本文介绍了无法在Seadist发行版中显示图例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次使用python进行绘图,并尝试按照以下代码在 seaborn 中绘制分布,但无法看到图例,即 test_label1 test_label1 .

I am new to plotting in python and trying following code to plot distribution in seaborn but unable to see the legend, i.e., test_label1 and test_label1 on the plot.

import matplotlib.pylab as plt
import seaborn as sns
import numpy as np

plt.figure("Test Plots")
lst1 = list(np.random.rand(10))
lst2 = list(np.random.rand(10))
sns.distplot(lst1, label='test_label1', color="0.25")
sns.distplot(lst2, label='test_label2', color="0.25")

plt.show()

推荐答案

因为您已经在 sns.distplot 中使用 label = 标记了地块,所以您拥有的全部要做的就是展示你的传奇.这是通过在 plt.show()

As you have already labelled your plots using label= inside your sns.distplot then all you have to do is show your legend. This is done by adding plt.legend() just before plt.show()

有关matplotlib图例的更多信息,请参见文档

More information on matplotlib legends can be found in the documentation

这篇关于无法在Seadist发行版中显示图例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆