In [1]:
import ps
Xs=ps.loadData('Xs.tl')

In [12]:
import json

In [6]:
aa=Xs[0][0]

In [5]:
aa.tolist()


Out[5]:
[0.3772687668982209, 0.12057939129176151]

In [37]:
def makeData(original):
    l=len(original)
    w=len(original[0])
    dic={}
    for i in range(l):
        datai=[]
        for j in range(w):
            datai.append(dict(value=original[i][j].tolist()))
        dic[i]=datai
    dic['label']=dic.keys() 
    return dic

In [38]:
Data=makeData(Xs)
with open('data.js','w+') as f:
    f.write('data=\n')
    json.dump(Data,f, sort_keys=True, indent=4)

In [41]:
def genCode(data):
    L=list()
    for i in data['label']:
        if i==0:
            continue;
        else:
            L.append(",{title:{'text':'the %s th iteration'},series:[{'data':data[%s]}]}"%(i,i))
    return ''.join(L)

In [56]:
import math
E=math.exp
def func(x,y):
    return 3*(1-x**2)*np.exp(-x**2-(y+1)**2)-10*(x/5.0-x**3-y**5)*np.exp(-x**2-y**2)-np.exp(-(x+1)**2-y**2)/3.0

In [73]:
%pylab
plt.rc('figure', figsize=(10, 10))


Using matplotlib backend: MacOSX
Populating the interactive namespace from numpy and matplotlib

In [58]:
delta = 0.025
x = np.arange(-4.0, 4.0, delta)
y = np.arange(-4.0, 4.0, delta)
X, Y = np.meshgrid(x, y)
Z=func(X,Y)

In [74]:
CS = plt.contour(X, Y, Z, 15, linewidths=0.5, colors='k')
CS = plt.contourf(X, Y, Z, 15, cmap=plt.cm.rainbow,
                  vmax=abs(Z).max(), vmin=-abs(Z).max())

In [52]:
X


Out[52]:
array([[-4.   , -3.975, -3.95 , ...,  3.925,  3.95 ,  3.975],
       [-4.   , -3.975, -3.95 , ...,  3.925,  3.95 ,  3.975],
       [-4.   , -3.975, -3.95 , ...,  3.925,  3.95 ,  3.975],
       ..., 
       [-4.   , -3.975, -3.95 , ...,  3.925,  3.95 ,  3.975],
       [-4.   , -3.975, -3.95 , ...,  3.925,  3.95 ,  3.975],
       [-4.   , -3.975, -3.95 , ...,  3.925,  3.95 ,  3.975]])

In [ ]: