z軸の値を3D棒グラフでそれぞれ表したいのですがうまくできないことと、オフィシャルサイトを見ても、dx,dy,dz云々、よく理解できず、コードを書くのに苦労しています。
python
1import numpy as np 2import matplotlib.pyplot as plt 3import math 4from mpl_toolkits.mplot3d import Axes3D 5from matplotlib import cm 6#import matplotlib.animation as animation 7 8#環境設定 9n=30 #tの範囲 10m=10 #偶数 11 12P = [[-1/2, 1/2, 1/2, 1/2],[0,0,0,0],[0,0,0,0],[0,0,0,0]] 13Q = [[0,0,0,0],[1/2, -1/2, 1/2, 1/2],[0,0,0,0],[0,0,0,0]] 14R = [[0,0,0,0],[0,0,0,0],[1/2, 1/2, -1/2, 1/2],[0,0,0,0]] 15S = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[1/2, 1/2, 1/2, -1/2]] 16 17t_list = [] 18x_list = [] 19y_list = [] 20 21phi_map = np.zeros((2*m+1, 2*m+1,4)) #np.zeros((行,列,[]の中身の数)) 22phi_map[m,m,0]= 1 23 24p_map=np.zeros([2*m+1,2*m+1]) 25 26for i in range(0,2*m+1): 27 p = np.dot(phi_map[i,i], np.conj(phi_map[i,i])) 28 p_map[i,i]=p 29 x_list.append(i) 30 y_list.append(i) 31#print(p_map) 32 33for t in range(0,n+1): 34 t_list.append(t) 35 if t == 0: 36 phi_map 37 p_map 38 else: 39 next_phi_map = np.zeros((2*m+1,2*m+1, 4)) 40 for x in range(0,2*m+1): 41 if x == 0: 42 for y in range(0,2*m+1): 43 if y == 0: 44 next_phi_map[x,y] = np.array([np.inner(P, phi_map[x+1,y]) + np.inner(R, phi_map[x,y+1])]) 45 elif y == 2*m: 46 next_phi_map[x,y] = np.array([np.inner(P, phi_map[x+1,y]) + np.inner(S, phi_map[x,y-1])]) 47 else: 48 next_phi_map[x,y] = np.array([np.inner(P, phi_map[x+1,y]) + np.inner(S, phi_map[x,y-1]) + np.inner(R, phi_map[x,y+1])]) 49 elif x == 2*m: 50 for y in range(0,2*m+1): 51 if y == 0: 52 next_phi_map[x,y] = np.array([np.inner(Q, phi_map[x-1,y]) + np.inner(R, phi_map[x,y+1])]) 53 elif y == 2*m: 54 next_phi_map[x,y] = np.array([np.inner(Q, phi_map[x-1,y]) + np.inner(S, phi_map[x,y-1])]) 55 else: 56 next_phi_map[x,y] = np.array([np.inner(Q, phi_map[x-1,y]) + np.inner(S, phi_map[x,y-1]) + np.inner(R, phi_map[x,y+1])]) 57 else: 58 for y in range(0,2*m+1): 59 if y == 0: 60 next_phi_map[x,y] = np.array([np.inner(P, phi_map[x+1,y]) + np.inner(Q, phi_map[x-1,y]) + np.inner(R, phi_map[x,y+1])]) 61 elif y == 2*m: 62 next_phi_map[x,y] = np.array([np.inner(P, phi_map[x+1,y]) + np.inner(Q, phi_map[x-1,y]) + np.inner(S, phi_map[x,y-1])]) 63 else: 64 next_phi_map[x,y] = np.array([np.inner(P, phi_map[x+1,y]) + np.inner(Q, phi_map[x-1,y]) + np.inner(R, phi_map[x,y+1]) + np.inner(S, phi_map[x,y-1])]) 65 p_map[x,y] = np.dot(next_phi_map[x,y], np.conj(next_phi_map[x,y])) 66 phi_map = next_phi_map 67 68 print(t,p_map) 69 70 #fig = plt.figure()#リアルタイムプロット 71 #ax = Axes3D(fig) 72 #X,Y = np.meshgrid(x_list,y_list) 73 74 #ax.set_xlabel("x") 75 #ax.set_ylabel("y") 76 #ax.set_zlabel("probability") 77 78 #ax.set_xlim(2*m,0) 79 #ax.set_ylim(0,2*m) 80 #ax.set_zlim(0,1) 81 #ax.plot_wireframe(X, Y, p_map, color ="red", linewidth=1) 82 #plt.pause(0.01) 83 #plt.cla() 84 85 86 87 88#3D_plot 89fig = plt.figure() 90ax = Axes3D(fig) 91X,Y = np.meshgrid(x_list,y_list) 92 93ax.set_xlabel("x") 94ax.set_ylabel("y") 95ax.set_zlabel("probability") 96 97ax.set_xlim(2*m,0) 98ax.set_ylim(0,2*m) 99ax.set_zlim(0,0.35) 100#ax = fig.add_subplot(111, projection="3d") 101surf = ax.plot_surface(X, Y, p_map, cmap =cm.coolwarm , linewidth=0) 102#ax.bar3d(x_list,y_list,p_map,width=0.1) 103fig.colorbar(surf) 104plt.show()
どなたか、bar3dについて、教えて頂けないでしょうか。。
宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/14 13:44
2018/05/14 13:48
2018/05/14 13:59 編集
2018/05/14 14:07
2018/05/14 14:09
2018/05/14 14:12
2018/05/14 14:16
2018/05/14 14:18
2018/05/14 14:39
2018/05/14 14:50
2018/05/14 14:51
2018/05/14 14:51
2018/05/14 14:54
2018/05/14 15:15