0

I'm going to see the behavior of ensembles of the data. a better way to visualize ensemble is by using the various uncertainty intervals along with the mean. We can compute the uncertainty interval at various percentile using the" st.scoreatpercentile" But using the following code, I encounter an error and figure is not plotted.

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as st

# generate some data
x = 100*np.sin([np.linspace(0,10,100)])
X = np.vstack([x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x,x])
e = 10*np.random.randn(20,100)
X_err = X+e
ll = st.scoreatpercentile(X_err, 10) # 10th percentile
ml = st.scoreatpercentile(X_err, 50) # 50th percentile
ul = st.scoreatpercentile(X_err, 90) # 90th percentile

plt.plot(ml,'g', lw=2, label= ' Median ' )
plt.plot(ul,'r', label= ' 90% ' )
plt.plot(ll,'b', label= ' 10% ' )
plt.xlabel( ' Time ' )
plt.ylabel( ' X ' )
plt.legend(loc= 'best' )
plt.show()
jlandercy
  • 7,183
  • 1
  • 39
  • 57
  • 1
    Welcome to SO. Could you update your post in order to comply with [mcve]. Mainly, your code is not correct because of `[...\...][1]` chars (I have edited your post to clean it). Copy-paste (no screenshot) the traceback of your error. Specify what is the expected output. – jlandercy Feb 19 '19 at 08:44
  • Additionnaly: I needed to correct `' best '` to `'best'` because it is a specific string and you can't add supernumerary spaces. Generally you should avoid adding extra space into your code. – jlandercy Feb 19 '19 at 08:51
  • 1
    I'm not sure what you're trying to do, but ml, ul, and ll are scalars, not arrays. So plt.plot won't plot anything because a line is defined by at least two points. If you want to draw boxplots, maybe have a look at seaborn ? – Ben Feb 19 '19 at 15:47
  • If for some reason you really want to stick with what you have here, replace plt.plot by plt.scatter. Something like this plots dots at x=0 and y at your values : plt.scatter(0,ml,c='g', label= ' Median ' ) plt.scatter(0,ul,c='r', label= ' 90% ' ) plt.scatter(0,ll,c='b', label= ' 10% ' ) – Ben Feb 19 '19 at 15:49

0 Answers0