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.
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
before plt.show()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.