你可以通过plt.errorbar
到FacetGrid.map
但它需要一个小包装的功能才能正常格式化参数(和明确地传递的类别顺序):
import numpy as np
from scipy import stats
import seaborn as sns
import matplotlib.pyplot as plt
# Reformat the tips dataset to your style
tips = sns.load_dataset("tips")
tips_agg = (tips.groupby(["day", "smoker"])
.total_bill.agg([np.mean, stats.sem])
.reset_index())
tips_agg["low"] = tips_agg["mean"] - tips_agg["sem"]
tips_agg["high"] = tips_agg["mean"] + tips_agg["sem"]
# Define a wrapper function for plt.errorbar
def errorbar(x, y, low, high, order, color, **kws):
xnum = [order.index(x_i) for x_i in x]
plt.errorbar(xnum, y, (y - low, high - y), color=color)
# Draw the plot
g = sns.factorplot(x="day", y="mean", col="smoker", data=tips_agg)
order = sns.utils.categorical_order(tips_agg["day"])
g.map(errorbar, "day", "mean", "low", "high", order=order)
当然,使用'plt.errorbar' – mwaskom
我试过以下内容:'g.map_dataframe(plt.errorbar,x =“followup(months)”,y =“probability”,yerr ='sd')'其中g是'FacetGrid',但没有任何东西添加到情节。 –
使用参数,而不是kwargs – mwaskom