标签未出现在 Seaborn distplot 中
Label is not appearing in Seaborn distplot
我正在使用 Seaborn 的 distplot()
函数,我并列了两个密度图——每个图在同一图中都有不同的颜色——我想给它们贴上标签。
我使用函数文档中提到的参数 'label'。
我的代码是:
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()
输出如下。里面没有标签:
只需添加
plt.legend()
有关详细信息,请参阅 documentation for legend()
and matplotlib's legend guide
之前 plt.show()
我正在使用 Seaborn 的 distplot()
函数,我并列了两个密度图——每个图在同一图中都有不同的颜色——我想给它们贴上标签。
我使用函数文档中提到的参数 'label'。
我的代码是:
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()
输出如下。里面没有标签:
只需添加
plt.legend()
有关详细信息,请参阅 documentation for legend()
and matplotlib's legend guide
之前 plt.show()