Home > Blockchain >  Python Pandas yerr from dataframe for plot
Python Pandas yerr from dataframe for plot

Time:05-16

I'm trying to create a simple plot from my dataframe. I've provided a reproducible example of what I'm doing now. It creates the bar chart I'd like buit without the y error bars to show the SEM of each mean value. How do I get the SEM values to show as error bars?

df = pd.DataFrame([{'Measures' : 'Pre Var 1',
       'Mean' : 2,
       'SEM' : 1}])

df[['Measures', 'Mean']].plot(x='Measures', kind='bar', yerr=df['SEM'])

This is what my code currently produces

This is what it produces

This is the desired graph

enter image description here

CodePudding user response:

try this :

import matplotlib.pyplot as plt


fig, ax = plt.subplots()

ax.bar(df['Measures'], df['Mean'], yerr=df['SEM'])
  • Related