Python 基于多索引数据帧的matplotlib绘制错误条

Python 基于多索引数据帧的matplotlib绘制错误条,python,pandas,matplotlib,errorbar,Python,Pandas,Matplotlib,Errorbar,我在pandas中有以下数据帧: >>>name Hour trt_level stress date value 0 D43 9 H control 2019-06-07 0.4561 1 D43 10 H control 2019-06-07 0.3216 2 D42 8 M stress 2019-0

我在pandas中有以下数据帧:

>>>name   Hour   trt_level    stress   date          value
0  D43    9         H         control  2019-06-07    0.4561
1  D43    10        H         control  2019-06-07    0.3216
2  D42    8         M         stress   2019-06-07    0.2143
3  D42    9         M         stress   2019-06-07    0.1342
4  D21    8         L         stress   2019-06-07    0.3214
...
我想创建带有错误条、mse/std的折线图,如下所示:

from:在我的例子中:X轴应该是小时,y轴应该是值,三行,每个治疗水平(trt_水平)一行,所以H,M,L的行

为此,我使用了函数groupby和agg:

data = df.groupby(['trt_level','Hour']).agg([np.mean, np.std])
data.head()

>>>                value
                   mean      std
trt_level  Hour   
H           7      0.231      0.0058
            8      0.212      0.0094
            9      0.431      0.1154
...


以treamtnet和hour为索引、值的平均值和标准值的gav eme数据库, 但问题是,当我试图绘制它时,我只得到一条顶部没有std的线:

data = data['value'] 
qual.plot(kind = "line", y = "mean", legend = False,  
          xerr = "std", title = "test", color='green')

当我想要的结果应该有三行在顶部的std时(最好是MES而不是std,但对于这个问题,我更关注三行和std的显示)

我的最终目标是得到一张更像这样的图表(为可怕的平局感到抱歉):


但是几乎所有的时间都在那里。您必须取消多索引数据帧的堆栈

import numpy as np
import pandas as pd
from matplotlib import pyplot as plt

#My test file contained at least two values per condition to calculate an SD value
#df = pd.read_csv("test.txt", sep = "\s{2,}") 

dfm = df.groupby(["trt_level","Hour"]).agg([np.mean, np.std])

dfm["value"].unstack(level=0).plot(y = "mean", yerr = "std", title = "TRT levels are really important!", color = list("rbg"))

plt.show()
样本输出

顺便说一句:
kind=“line”
不必指定,它是默认值。熊猫文档列出了所有