In [1]:
%load_ext autoreload
import numpy as np
%aimport FE
%aimport common_meshes
import matplotlib.pyplot as plt
from matplotlib import animation
import triangle
%matplotlib inline
print(plt.style.available)
plt.style.use('seaborn-paper')


['fivethirtyeight', 'bmh', 'ggplot', 'seaborn-ticks', 'seaborn-bright', 'seaborn-white', 'seaborn-deep', 'seaborn-darkgrid', 'classic', 'seaborn-pastel', 'seaborn-talk', 'seaborn-whitegrid', 'seaborn-paper', 'seaborn-dark', 'seaborn-muted', 'seaborn-notebook', 'seaborn-dark-palette', 'dark_background', 'grayscale', 'seaborn-poster', 'seaborn-colorblind']

In [ ]:
"""Example from matplotlib website"""

def update_line(num, data, line):
    line.set_data(data[...,:num])
    return line,

fig1 = plt.figure()

data = np.random.rand(2, 25)
l, = plt.plot([], [], 'r-')
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.xlabel('x')
plt.title('test')
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
    interval=50, blit=True)
line_ani.save('lines.mp4')

fig2 = plt.figure()

x = np.arange(-9, 10)
y = np.arange(-9, 10).reshape(-1, 1)
base = np.hypot(x, y)
ims = []
for add in np.arange(15):
    ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),))

im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
    blit=True)
im_ani.save('im.mp4', metadata={'artist':'Guido'})

#plt.show()

In [2]:
def plotMesh(mesh):
    x = mesh['vertices'][:,0]
    y = mesh['vertices'][:,1]
    plt.axes().set_aspect('equal')
    plt.triplot(x, y, mesh['triangles'])
    return

In [58]:
t = np.arange(0., 1., 0.01)
pt_list = np.array([[0.5-x/2.,0.5+x/2.] for x in t])

In [59]:
im = []
plt.xlim(0, 1)
plt.ylim(0, 1)
plt.title('test 1')
fig = plt.figure()
for pt in pt_list:
    print(pt)
    sklt = {'vertices': np.array([[0.,0.], [1.,0.], pt]),
            'triangles': np.array([[0,1,2]]),
            'segments': np.array([[0], [1], [2]])}
    plt.axes().set_aspect('equal')
    sk_x = sklt['vertices'][:,0]
    sk_y = sklt['vertices'][:,1]
    mesh = triangle.triangulate(sklt, 'qa0.0005')
    evecs = FE.findEigs(mesh, 5)[1]
    eigvec_1 = evecs[:,1]
    contours = np.linspace(np.min(eigvec_1)-0.01, np.max(eigvec_1)+0.01, 50)
    #plt.triplot(sk_x, sk_y, color='k')
    x = mesh['vertices'][:,0]
    y = mesh['vertices'][:,1]
    im.append((plt.tricontour(x, y, eigvec_1, contours, 
                             colors=('k',), linestyles='solid').collections +
               plt.triplot(sk_x, sk_y, color='k')))
im_ani = animation.ArtistAnimation(fig, im + im[::-1], interval=33, repeat_delay=10,
                                   blit=True)
im_ani.save('hot_spots_1.mp4', metadata={'artist':'Neal Coleman'})


[ 0.5  0.5]
             time: 0.11187505722045898
[ 0.495  0.505]
             time: 0.11595392227172852
[ 0.49  0.51]
             time: 0.12259793281555176
[ 0.485  0.515]
             time: 0.1254901885986328
[ 0.48  0.52]
             time: 0.11061239242553711
[ 0.475  0.525]
             time: 0.11753249168395996
[ 0.47  0.53]
             time: 0.1535499095916748
[ 0.465  0.535]
             time: 0.14577794075012207
[ 0.46  0.54]
             time: 0.12521719932556152
[ 0.455  0.545]
             time: 0.1360163688659668
[ 0.45  0.55]
             time: 0.1298203468322754
[ 0.445  0.555]
             time: 0.1280078887939453
[ 0.44  0.56]
             time: 0.12572908401489258
[ 0.435  0.565]
             time: 0.12482929229736328
[ 0.43  0.57]
             time: 0.13806414604187012
[ 0.425  0.575]
             time: 0.14125895500183105
[ 0.42  0.58]
             time: 0.12491154670715332
[ 0.415  0.585]
             time: 0.1229856014251709
[ 0.41  0.59]
             time: 0.14709687232971191
[ 0.405  0.595]
             time: 0.13655543327331543
[ 0.4  0.6]
             time: 0.1431424617767334
[ 0.395  0.605]
             time: 0.14069628715515137
[ 0.39  0.61]
             time: 0.13988423347473145
[ 0.385  0.615]
             time: 0.1405501365661621
[ 0.38  0.62]
             time: 0.14226460456848145
[ 0.375  0.625]
             time: 0.13858318328857422
[ 0.37  0.63]
             time: 0.13569879531860352
[ 0.365  0.635]
             time: 0.1455364227294922
[ 0.36  0.64]
             time: 0.1493377685546875
[ 0.355  0.645]
             time: 0.17357635498046875
[ 0.35  0.65]
             time: 0.15087461471557617
[ 0.345  0.655]
             time: 0.24693727493286133
[ 0.34  0.66]
             time: 0.197174072265625
[ 0.335  0.665]
             time: 0.18905997276306152
[ 0.33  0.67]
             time: 0.1886911392211914
[ 0.325  0.675]
             time: 0.15363144874572754
[ 0.32  0.68]
             time: 0.16910576820373535
[ 0.315  0.685]
             time: 0.16147279739379883
[ 0.31  0.69]
             time: 0.18530035018920898
[ 0.305  0.695]
             time: 0.20470452308654785
[ 0.3  0.7]
             time: 0.16245627403259277
[ 0.295  0.705]
             time: 0.1703171730041504
[ 0.29  0.71]
             time: 0.17442822456359863
[ 0.285  0.715]
             time: 0.17041230201721191
[ 0.28  0.72]
             time: 0.17516469955444336
[ 0.275  0.725]
             time: 0.18442201614379883
[ 0.27  0.73]
             time: 0.1881694793701172
[ 0.265  0.735]
             time: 0.17846369743347168
[ 0.26  0.74]
             time: 0.18497061729431152
[ 0.255  0.745]
             time: 0.18053102493286133
[ 0.25  0.75]
             time: 0.19630050659179688
[ 0.245  0.755]
             time: 0.16684341430664062
[ 0.24  0.76]
             time: 0.17897725105285645
[ 0.235  0.765]
             time: 0.1904311180114746
[ 0.23  0.77]
             time: 0.1900784969329834
[ 0.225  0.775]
             time: 0.19286251068115234
[ 0.22  0.78]
             time: 0.2207775115966797
[ 0.215  0.785]
             time: 0.1823291778564453
[ 0.21  0.79]
             time: 0.23317599296569824
[ 0.205  0.795]
             time: 0.19515013694763184
[ 0.2  0.8]
             time: 0.20206928253173828
[ 0.195  0.805]
             time: 0.20133519172668457
[ 0.19  0.81]
             time: 0.1996469497680664
[ 0.185  0.815]
             time: 0.2153034210205078
[ 0.18  0.82]
             time: 0.20189881324768066
[ 0.175  0.825]
             time: 0.20108270645141602
[ 0.17  0.83]
             time: 0.20260858535766602
[ 0.165  0.835]
             time: 0.21116924285888672
[ 0.16  0.84]
             time: 0.20069265365600586
[ 0.155  0.845]
             time: 0.20328235626220703
[ 0.15  0.85]
             time: 0.2309401035308838
[ 0.145  0.855]
             time: 0.2123277187347412
[ 0.14  0.86]
             time: 0.2135310173034668
[ 0.135  0.865]
             time: 0.21156048774719238
[ 0.13  0.87]
             time: 0.2050182819366455
[ 0.125  0.875]
             time: 0.21050405502319336
[ 0.12  0.88]
             time: 0.2160181999206543
[ 0.115  0.885]
             time: 0.22147107124328613
[ 0.11  0.89]
             time: 0.22421789169311523
[ 0.105  0.895]
             time: 0.2963905334472656
[ 0.1  0.9]
             time: 0.24266624450683594
[ 0.095  0.905]
             time: 0.22928476333618164
[ 0.09  0.91]
             time: 0.22937297821044922
[ 0.085  0.915]
             time: 0.22519302368164062
[ 0.08  0.92]
             time: 0.23837566375732422
[ 0.075  0.925]
             time: 0.23917365074157715
[ 0.07  0.93]
             time: 0.24886465072631836
[ 0.065  0.935]
             time: 0.2677803039550781
[ 0.06  0.94]
             time: 0.25394344329833984
[ 0.055  0.945]
             time: 0.23741388320922852
[ 0.05  0.95]
             time: 0.2731747627258301
[ 0.045  0.955]
             time: 0.3003718852996826
[ 0.04  0.96]
             time: 0.2494981288909912
[ 0.035  0.965]
             time: 0.2651181221008301
[ 0.03  0.97]
             time: 0.2573521137237549
[ 0.025  0.975]
             time: 0.2717459201812744
[ 0.02  0.98]
             time: 0.2576303482055664
[ 0.015  0.985]
             time: 0.2918076515197754
[ 0.01  0.99]
             time: 0.2642343044281006
[ 0.005  0.995]
             time: 0.2543661594390869

In [ ]: