0

I have constructed a MultiIndex column Dataframe and plot it in grouped horizontal bars. The grouping is on MultiIndex level 1, which I have solved with unstack() for the plot. I would like to add the xerr bar to the plot, however it is not displayed.

Here is the dataframe:

    level_0: observer_1           observer_2              observer_3
    level_1: meas1 meas2 meas3    meas1 meas2 meas3       meas1 meas2 meas3
index: 
val          3      1     5        2    0.5    4           2     2    4.5
std          0.1    0.2   0.01     0.15  0.01  0.2         0.03  0.1  0.01   

Here is my code and the plot:

dfSTD = df.loc['std',:].to_frame()
dfVal = df.loc['val',:].to_frame()
dfVal.unstack(level=0).plot(kind='barh', ax=axis[0], xerr=dfSTD.unstack(level=0))

Horizontal Barplot

Moiraine24
  • 369
  • 1
  • 5
  • 16
  • Can you add some code to create a dummy df we can play with? See also: https://pandas.pydata.org/pandas-docs/stable/visualization.html#plotting-with-error-bars Why is your std dev transposed? – Evan Aug 10 '18 at 14:09
  • @Evan I have read this documentation. I figure something does not connect because of the unstack(). The transpose was because otherwise python threw an error that there is a dimension mismatch and accepted the transpose. – Moiraine24 Aug 16 '18 at 08:36

1 Answers1

0

Apparently, the values have to be taken from the dataframe, similar to this case here: Plotting error bars

So the plot command I was looking for is this:

dfVal.unstack(level=0).plot(kind='barh', ax=axis[0], xerr=dfSTD.unstack(level=0).values.T)

enter image description here

Moiraine24
  • 369
  • 1
  • 5
  • 16