0

Here I have a dataframe, and I want to plot the error bar plots

import pandas as pd
import matplotlib.pyplot as plt

rows = ["N", "W", "E", "S"]
cols = ["x_mean","y_mean","x_se","y_se"]
data = ([50, 40, 2, 5], [30, 34, 3, 5], [60, 45, 8, 3], [80, 60, 5, 5])

df = pd.DataFrame(data, index = rows, columns = cols)

   x_mean  y_mean  x_se  y_se
N      50      40     2     5
W      30      34     3     5
E      60      45     8     3
S      80      60     5     5

# plot
df[["x_mean", "y_mean"]].plot(kind = "bar", yerr = df[["x_se", "y_se"]], rot = 1)

However, the error bar does not show up, any hint or help is welcome

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Cooper
  • 81
  • 5
  • I think there is a bit different there? He has only 1 standard error but I need to use 2 – Cooper Oct 08 '21 at 16:13
  • It's not different. It's exactly the same `df[["x_mean", "y_mean"]]` is the same as `dfp` and `df[["x_se", "y_se"]]` is the same as `dfe`. As such, it should work, and isn't. I can't tell why it's not working so I'll reopen the question. – Trenton McKinney Oct 08 '21 at 16:31
  • 1
    I know why it's not working. the columns must have the same name for the error bars and the data. So this is in fact a duplicate. `dfe = df[["x_se", "y_se"]].rename({'x_se': 'x_mean', 'y_se': 'y_mean'}, axis=1)` and `yerr=dfe`. [Code and Plot](https://i.stack.imgur.com/JaZmW.png) – Trenton McKinney Oct 08 '21 at 16:35
  • 1
    What about `yerr=df[["x_se", "y_se"]].to_numpy().T` as in (https://stackoverflow.com/a/26634872/15497888)? – Henry Ecker Oct 08 '21 at 16:44

0 Answers0