Issue
I have data frame which has data about mean value of different group and their std, similar to this:
index timestamp mean1 std1 mean2 std2 mean3 std3
0 2022/11/01 0.542 0.07 0.729 0.21 0.375 0.08
1 2022/11/02 0.623 0.05 0.811 0.04 0.211 0.11
...
I want to plot the three means per day and to display the std. For that I have seen that I can use the plot function of matplotlib, and to add the variable "yerr" and to put the name of the std columns. However, I keetp getting this error:
'Line2D' object has no property 'yerr'
I have used this script:
from matplotlib.lines import Line2D
ax=plt.figure(figsize=(15,8))
plt.plot(df.iloc[:,1],color='tab:blue',yerr='std1',linestyle='-',linewidth=1.8)
plt.plot(df.iloc[:,3],color='black',yerr='std2',linestyle='-',linewidth=1.8)
plt.plot(df.iloc[:,5],color='tab:red',,yerr='std3',linestyle='-',linewidth=1.8)
plt.xticks(fontsize=16, rotation=90)
plt.yticks(fontsize=16)
how can I fix it and display the error on top of the lines? the script works when I don't add the yerr parameter.
Solution
You are using 'plt.plot()' to try and include the error bars, yet the linked function is 'plt.errorbar()'. I think that 'plt.plot()' does not have the optional argument 'yerr' and that's the reason for the error. I suggest substituting your 'plt.plot()' by 'plt.errorbar()' and it should work:)
Answered By - Oski
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.