Python Forum
error bars with dataframe and pandas
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error bars with dataframe and pandas
#1
Hello everyone,

hope someone can give me an advice.

I have 3 dataframes with different values, each with time (x-values) and y values.
I calculated the average and the standard deviation for the error bars with
mean = dataframe.groupby(['time','y values']).agg({'y values':'mean'}).reset_index()
std = dataframe.groupby(['time','y values']).agg({'y values':'std'}).reset_index()
mean['err'] = std['y values']
Then I tried to plot everything with

fig, (ax1) = plt.subplots(1, 1) 
mean.plot(x='time', y='y values', style='.', color='b', legend=True, label='test', ax=ax1) 
ax1.errorbar(mean.index, mean['time'], yerr=mean['err'])
ax1.legend(loc='lower right', fancybox=True, fontsize=9)
ax1.yaxis.set_label_text("y values")  
ax1.xaxis.set_label_text("Time (h)")
ax1.set_title("test")  
But the error bars are not shown in the right way. I tried it already with mean.plot(...yerr=' '), but the same result. Someone have an idea?
Reply
#2
What are you wanting, and what are you getting?
Check Matplotlib documentation
Reply
#3
Hi,

here you find the pictures
error bars should be and actual

the first one is, how the error bars should be and the second and third how they are.
I have absolutely no idea anymore.
Reply
#4
Hard to tell, what is the shape of mean? std?
Have you tried making x and y in the errorbar call just mean and std, and no other arguments? Or mean.values and std.values and no other arguments?
Reply
#5
Found the mistake. I did
[pyhton]fig, (ax1) = plt.subplots(1, 1) ....[/[pyhton]]

and then later again
[pyhton]fig, (ax1) = plt.subplots(1, 1) ....[/[pyhton]]

Now I changes the second subplots ax1 to ax2 and everything works fine.
Thank you for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  HTML Decoder pandas dataframe column mbrown009 3 962 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  How to create a plot with line graphs and vertical bars devansing 6 2,254 Feb-28-2023, 05:38 PM
Last Post: devansing
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 1,090 Jan-06-2023, 10:53 PM
Last Post: haihal
  pip install pandas ERROR pythondudu 7 32,931 May-24-2022, 06:14 AM
Last Post: Marya_475
  Pandas Dataframe Filtering based on rows mvdlm 0 1,396 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 2,269 Mar-02-2022, 08:22 AM
Last Post: mcva
  Pandas dataframe comparing anto5 0 1,243 Jan-30-2022, 10:21 AM
Last Post: anto5
  PANDAS: DataFrame | Replace and others questions moduki1 2 1,758 Jan-10-2022, 07:19 PM
Last Post: moduki1
  PANDAS: DataFrame | Saving the wrong value moduki1 0 1,525 Jan-10-2022, 04:42 PM
Last Post: moduki1
  update values in one dataframe based on another dataframe - Pandas iliasb 2 9,099 Aug-14-2021, 12:38 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020