【发布时间】:2016-06-03 00:11:46
【问题描述】:
seaborn 中最酷的东西之一是 boxplot + stripplot 组合:
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
tips = sns.load_dataset("tips")
sns.stripplot(x="day", y="total_bill", hue="smoker",
data=tips, jitter=True,
palette="Set2", split=True,linewidth=1,edgecolor='gray')
sns.boxplot(x="day", y="total_bill", hue="smoker",
data=tips,palette="Set2",fliersize=0)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.);
不幸的是,正如您在上面看到的,它产生了双重图例,一个用于箱线图,一个用于条形图。显然,它看起来很荒谬和多余。但我似乎找不到摆脱stripplot 传奇的方法,只留下boxplot 传奇。也许,我可以以某种方式从plt.legend 中删除项目,但我在文档中找不到它。
【问题讨论】:
标签: python matplotlib legend seaborn