簡體   English   中英

標簽未出現在 Seaborn distplot 中

[英]Label is not appearing in Seaborn distplot

我正在使用 Seaborn 的distplot()函數,我將兩個密度圖並置 - 每個在同一圖中具有不同的顏色 - 我想標記它們。

我使用函數文檔中提到的參數“標簽”。

我的代碼是:

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()

有關更多詳細信息,請參閱legend()和 matplotlib 的圖例指南的文檔

plt.show()之前

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM