Create a gist now

Instantly share code, notes, and snippets.

@jul /takens.py
Last active Sep 20, 2015

What would you like to do?
takens for everything
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.finance import quotes_historical_yahoo_ohlc
from random import randint
import matplotlib.cm as cmx
import matplotlib.colors as colors
date1 = (2013, 2, 1)
date2 = (2015, 7, 12)
quotes = quotes_historical_yahoo_ohlc('GE', date1, date2)
opening = [ q[1] for q in quotes[0:]]
def takens(time_serie, homothetia=1):
q=np.array(time_serie)
a=np.array(q)
b=np.roll(a,1)
c=np.roll(b,1)
d=np.roll(c,1)
e=np.roll(d,1)
da=b-a
db=c-b
dc=d-c
dd=e-d
d2a=db-da
d2b=dc-db
d2c=dd-dc
fig = plt.figure()
ax = fig.gca(projection='3d')
step=1
jet = cm = plt.get_cmap('PRGn')
cNorm = colors.Normalize(vmin=0, vmax=len(a))
scalarMap = cmx.ScalarMappable(norm=cNorm, cmap=jet)
max_in_data = max(d2c)
for i in range(0,int(len(da)),step):
color = scalarMap.to_rgba(i)
norm = 1.0*sum(
[d2a[i:i+step]**2,d2b[i:i+step]**2,d2c[i:i+step]**2]
)**(.5)/(
3*(max_in_data**2) **.5
) * homothetia
#ax.plot(da[i:i+step], db[i:i+step],dc[i:i+step],
#alpha=.2,color=color )
ax.quiver(
da[i:i+step], db[i:i+step], dc[i:i+step],
d2a[i:i+step],d2b[i:i+step],d2c[i:i+step],
alpha=float(1.0*i/len(da)),
length=norm,
color = scalarMap.to_rgba(i)
)
plt.show()
takens(opening,3)
takens([ randint(0,32) for i in range(2000)],6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment