标签未出现在 Seaborn distplot 中

use*_*077 3 python label pandas density-plot seaborn

我正在使用distplot()Seaborn的功能,我将两个密度图并置 - 每个在同一图中具有不同的颜色 - 我想标记它们。

我使用函数文档中提到的参数“标签”。

我的代码是:

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()
Run Code Online (Sandbox Code Playgroud)

输出如下。里面没有标签:

在此处输入图片说明

Diz*_*ahi 5

只需添加

plt.legend()
Run Code Online (Sandbox Code Playgroud)

有关更多详细信息,请参阅文档legend()和 matplotlib 的图例指南

plt.show()