2

I ran an lstm model 10 times and averaged the values to get the mean and that became my predicted value. I calculated the standard diviation of each row and added it to my dataframe (test_iterations)that contains my predicted values. I now want to plot error bars so my graph can look like this (that was done in excel) enter image description here

But when i use the following code i get a graph that looks like this

plt.errorbar(test_iterations['Mean'].values, 
                     test_iterations['Mean'].values,
                     yerr = test_iterations['Stdv'].values,
                     fmt='-o')

enter image description here

I'm not sure what am doing is even right because i added x and y values on the code of the same thing but wasn't sure what to add there

Denise
  • 153
  • 3
  • 15
  • Does this answer your question? [How to add error bars to a grouped bar plot?](https://stackoverflow.com/questions/63866002/how-to-add-error-bars-to-a-grouped-bar-plot) – Karthik Sep 17 '20 at 07:42

1 Answers1

2

The first argument of plt.errorbar() is the x coordinates of the points to plot. In your case, it is the rank of the value.

Try this:

import numpy as np

plt.errorbar(np.arange(len(test_iterations['Mean'])),
             test_iterations['Mean'].values,
             yerr=test_iterations['Stdv'].values,
             fmt='-o')
Gustave Coste
  • 677
  • 5
  • 19