python - Plot using pandas -


i have event times in list , plot exponentially weighted moving average of them. can using following code.

import numpy np import matplotlib.pyplot plt  print "code runnning" a=0.01 l = [3.0,7.0,10.0,20.0,200.0] y = np.zeros(1000) item in l:         y[item]=1 s = np.zeros(1000) x = np.linspace(0,1000,1000) in xrange(1000):     s[i] = a*y[i-1]+(1-a)*s[i-1] plt.plot(x, s) plt.show() 

this horrible way use python however. what's right way this? possible without making these sparse arrays?

the output should this.

enter image description here

pandas comes mind task:

import pandas pd  l = [3.0,7.0,10.0,20.0,200.0] s = pd.series(np.ones_like(l), index=l) y = s.reindex(range(1000), fill_value=0) pd.ewma(y, 199).plot() 

the period 199 related parameter alpha 0.01 n=2/(a+1). result: enter image description here


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -