Adding error bars to predicted values in python

Viewed 264

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

1 Answers

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')
Related