📅  最后修改于: 2022-03-11 14:57:31.160000             🧑  作者: Mango
import matplotlib.pyplot as plt
import seaborn as sns
df = sns.load_dataset("iris")
ax = sns.boxplot(y="species", x="sepal_length", data=df)
medians = df.groupby(['species'])['sepal_length'].median().values
nobs = df['species'].value_counts().values
nobs = [str(x) for x in nobs.tolist()]
nobs = ["n: " + i for i in nobs]
pos = range(len(nobs))
for tick,label in zip(pos,ax.get_yticklabels()):
ax.text(medians[tick],tick,nobs[tick],color='black', verticalalignment = "bottom")
sns.despine()
plt.show();