我想在seaborn中绘制一个factorplot但是手动提供误差条而不是让seaborn计算它们.
model output feature mean std
0 first two a 9.00 2.00
1 first one b 0.00 0.00
2 first one c 0.00 0.00
3 first two d 0.60 0.05
...
77 third four a 0.30 0.02
78 third four b 0.30 0.02
79 third four c 0.10 0.01
我正在使用这个seaborn命令来生成图:
g = sns.factorplot(data=pltdf, x='feature', y='mean', kind='bar',
col='output', col_wrap=2, sharey=False, hue='model')
g.set_xticklabels(rotation=90)
但是,我无法弄清楚如何让seaborn使用’std’列作为错误栏.不幸的是,重新计算相关数据帧的输出将非常耗时.
这有点类似于这个q:
Plotting errors bars from dataframe using Seaborn FacetGrid
除了我无法弄清楚如何使用matplotlib.pyplot.bar函数.
有没有办法使用seaborn factorplot或FacetGrid结合matplotlib?
谢谢!
解决方法:
你可以做点什么
import seaborn as sns
import matplotlib.pyplot as plt
from scipy.stats import sem
tips = sns.load_dataset("tips")
tip_sumstats = (tips.groupby(["day", "sex", "smoker"])
.total_bill
.agg(["mean", sem])
.reset_index())
def errplot(x, y, yerr, **kwargs):
ax = plt.gca()
data = kwargs.pop("data")
data.plot(x=x, y=y, yerr=yerr, kind="bar", ax=ax, **kwargs)
g = sns.FacetGrid(tip_sumstats, col="sex", row="smoker")
g.map_dataframe(errplot, "day", "mean", "sem")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。