我可以說,我喜歡它,當人們包括樣本數據集。一個健康的+1給你!
import seaborn as sns, numpy as np
sns.set_style("whitegrid")
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
medians = tips.groupby(['day'])['total_bill'].median().values
median_labels = [str(np.round(s, 2)) for s in medians]
pos = range(len(medians))
for tick,label in zip(pos,ax.get_xticklabels()):
ax.text(pos[tick], medians[tick] + 0.5, median_labels[tick],
horizontalalignment='center', size='x-small', color='w', weight='semibold')
感謝一個greant回答伯尼! – user308827
乾杯,隊友。快樂的編碼給你! – bernie
請注意,中位數[tick]後0.5的影響對數據的比例敏感。對於我的小規模,它把白色文本推到了白色背景中,並花了我一段時間才弄清楚爲什麼它沒有顯示。根據需要調整0.5。 –