简体   繁体   English

标签未出现在 Seaborn distplot 中

[英]Label is not appearing in Seaborn distplot

I am using the distplot() function of Seaborn and I am juxtaposing two density plots -- each with a different color in the same plot -- and I want to label them.我正在使用 Seaborn 的distplot()函数,我将两个密度图并置 - 每个在同一图中具有不同的颜色 - 我想标记它们。

I use the argument 'label', referred in the documentation of the function.我使用函数文档中提到的参数“标签”。

My code is:我的代码是:

Response4_mask = train_with_response['Response4'] == 1
not_Response4_mask = train_with_response['Response4'] != 1

plt.figure()

sns.distplot(a = train_imp_with_response[Response4_mask]['Family_Hist_4'], hist = True, color = 'red', label = 'Response4')
sns.distplot(a = train_imp_with_response[not_Response4_mask]['Family_Hist_4'], hist = True, label = 'not_Response4')

plt.title('Family_Hist_4')

plt.tight_layout()
plt.show()

The output is below.输出如下。 There is no label in it:里面没有标签:

在此处输入图片说明

Just add只需添加

plt.legend()

See documentation for legend() and matplotlib's legend guide for more details有关更多详细信息,请参阅legend()和 matplotlib 的图例指南的文档

before plt.show()plt.show()之前

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM