你可以通過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)
![enter image description here](https://i.stack.imgur.com/CS2vF.png)
當然,使用'plt.errorbar' – mwaskom
我試過以下內容:'g.map_dataframe(plt.errorbar,x =「followup(months)」,y =「probability」,yerr ='sd')'其中g是'FacetGrid',但沒有任何東西添加到情節。 –
使用參數,而不是kwargs – mwaskom