【发布时间】:2021-12-09 18:49:13
【问题描述】:
我一直在尝试将图例添加到下面的代码中。 当我添加“标签”时,它应该可以工作。但它只是不会显示,不知道我做错了什么。
使用的包
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import scipy.stats as stats
from scipy.stats import kruskal
from sklearn.datasets import load_iris
Df1 = pd.read_csv(r"C:\Users\pc admin\Desktop\SUTD Programming\Data Wrangling\Personal Assigment\IBM Data.csv", header=0)
plt.figure(figsize=(20,8))
plt.style.use('seaborn-colorblind')
plt.grid(True, alpha=0.5)
sns.kdeplot(Df1.loc[Df1['Attrition'] == 'No', 'JobSatisfaction'], **label = "Previous-Employee"**)
sns.kdeplot(Df1.loc[Df1['Attrition'] == 'Yes', 'JobSatisfaction'], **label ="Current-Employees"**)
plt.xlabel('JobSatisfaction')
plt.xlim(left=0)
plt.ylabel('Density')
plt.title('Distance From Home Distribution in Percent by Attrition Status');
【问题讨论】:
标签: python matplotlib seaborn legend