animationとして、以下のコード結果を動画で保存したいのですが、以下のようなエラーが出てしまいました。
いくつかネットで調べたのですが、おそらく
def plot(data):
plt cla()
のやり方の方が今回は良いかもしれませんが、以下は違う書き方を自分がしていると思います。
python
1import numpy as np 2import matplotlib.pyplot as plt 3import math 4#from mpl_toolkits.mplot3d import Axes3D 5import matplotlib.animation as animation 6 7fig = plt.figure() 8ims=[] 9 10#環境設定 11n=100 12m=100 13theta = 3*(math.pi)/12 14 15P = [[np.cos(theta),np.sin(theta)],[0,0]] 16Q = [[0,0],[np.sin(theta),-np.cos(theta)]] 17x_list=[]#xline 18t_list=[]#time 19p_list=[]#probability 20s_list=[]#state 21a = 1/math.sqrt(2) 22b = 1j/math.sqrt(2) 23 24for x in range(0,2*m+1): 25 if x == m: 26 phi = [a ,b] 27 else: 28 phi = [0,0] 29 p = np.dot(phi,np.conj(phi)) 30 31 x_list.append(x) 32 s_list.append(phi) 33 p_list.append(p) 34 35 36for t in range(0,n+1): 37 t_list.append(t) 38 if t ==0: 39 s_list 40 p_list 41 else: 42 next_s_list = [0]*len(s_list) #s_listと同じ要素の数ですべて0を用意(初期化) 43 for x in range(0,2*m+1): 44 if x == 0: 45 next_s_list[0] = np.inner(P, s_list[1]) 46 47 elif x == 2*n: 48 next_s_list[2*m] = np.inner(Q, s_list[2*m-1]) 49 50 else: 51 next_s_list[x] = np.inner(P, s_list[x+1]) + np.inner(Q, s_list[x-1]) 52 p_list[x] = np.dot(next_s_list[x],np.conj(next_s_list[x])) 53 s_list = next_s_list 54 55 56 #確率の挙動をみたいなら 57 print(t,s_list) 58 plt.xlabel("x") 59 plt.ylabel("probability") 60 plt.ylim([0,0.1]) 61 plt.xlim([-m,3*m]) 62 line = plt.plot(x_list,np.real(p_list),color="red",linewidth=0.3) 63 ims.append([line]) 64 65ani = animation.ArtistAnimation(fig,ims, interval=100) 66ani.save("quantumwalk.gif")
ちなみに、コード自体は計算されており、エラーが以下のように出ました。
ValueError: outfile must be *.htm or *.html
結構、調べたんですけど、力足らずで申し訳ないです。。
ご指導の程、宜しくお願いします。。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/09 15:41