Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向Seaborn FactoryPlot添加简单错误条_Python_Plot_Seaborn - Fatal编程技术网

Python 向Seaborn FactoryPlot添加简单错误条

Python 向Seaborn FactoryPlot添加简单错误条,python,plot,seaborn,Python,Plot,Seaborn,我有一个从汇总表生成的factorplot,而不是原始数据: 使用以下代码: sns.factorplot(col="followup", y="probability", hue="next intervention", x="age", data=table_flat[table_flat['next intervention']!='none'],

我有一个从汇总表生成的
factorplot
,而不是原始数据:

使用以下代码:

sns.factorplot(col="followup", y="probability", hue="next intervention", x="age", 
               data=table_flat[table_flat['next intervention']!='none'], 
               facet_kws={'ylim':(0,0.6)})
这里绘制的是汇总表中的平均值,但我还想绘制可信区间,其上限和下限在另外两列中指定。该表如下所示:


是否有一种方法,可以使用
factorplot
返回的
FacetGrid
将错误条固定到点?

您可以将
plt.errorbar
传递到
FacetGrid.map
,但它需要一个小包装函数来正确地重新格式化参数(并显式传递类别顺序):


当然,使用
plt.errorbar
我尝试了以下方法:
g.map\u数据帧(plt.errorbar,x=“followup(months)”,y=“probability”,yerr='sd')
其中g是
FacetGrid
,但没有添加任何内容到绘图中。使用args,而不是kwargs如果我指定了
色调,我如何将不同的颜色传递到条上,例如,当一个图形中有两条线时?
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)