2017-04-21 76 views
0

有2個參數,我想嘗試不同的值:可視化2個參數,其結果

a = [0.0, 0.5, 0.6] # len == 3 
b = [0.0, 0.02 , 0.05, 0.1] # len == 4 

對於的每個值,嘗試B的每一個值。 這與3 * 4 = 12個不同的結果。

我的數據來自於

res = [(0.0, 0.0, res1), (0.0, 0.02, res2), ...] 

格式有什麼辦法,我可以想像整齊這個?我正在考慮輪廓/熱圖或3d平面,但很遺憾,我無法讓它工作。

+0

等高線地圖肯定會是一個不錯的選擇。請在代碼中顯示「無法工作」,也許我們可以幫助實現它。 – DyZ

回答

1

有很多不同的選擇。任何情況下的第一步都需要將您的res列表轉換爲一個numpy數組。

對於許多情節就像imshowpcolor(mesh)contourf,你需要有三個二維陣列,您可以通過您的輸入數組的重塑獲得(假設它是正確的排序)。

下面顯示了你有一些選擇:

enter image description here

res = [(0.0, 0.0, 0.5), (0.0, 0.02, 0.7), (0.0, 0.05, 0.6), (0.0, 0.10, 0.8), 
     (0.5, 0.0, 0.4), (0.5, 0.02, 0.6), (0.5, 0.05, 0.5), (0.5, 0.10, 0.7), 
     (0.6, 0.0, 0.3), (0.6, 0.02, 0.5), (0.6, 0.05, 0.4), (0.6, 0.10, 0.6)] 

import matplotlib.pyplot as plt 
import numpy as np 

res = np.array(res) 
A = res[:,0].reshape(3,4) #A in y direction 
B = res[:,1].reshape(3,4) 
Z = res[:,2].reshape(3,4) 

fig, ((ax, ax2), (ax3, ax4)) = plt.subplots(2,2) 
#imshow 
im = ax.imshow(Z, origin="lower") 
ax.set_xticks(range(len(Z[0,:]))) 
ax.set_yticks(range(len(Z[:,0]))) 
ax.set_xticklabels(B[0,:]) 
ax.set_yticklabels(A[:,0]) 

#pcolormesh, first need to extend the grid 
bp = np.append(B[0,:], [0.15]) 
ap = np.append(A[:,0], [0.7]) 
Bp, Ap = np.meshgrid(bp, ap) 
ax2.pcolormesh(Bp, Ap, Z) 

#contour 
ax3.contourf(B, A, Z, levels=np.linspace(Z.min(), Z.max(),5)) 
#scatter 
ax4.scatter(res[:,1], res[:,0], c=res[:,2], s=121) 

ax.set_title("imshow") 
ax2.set_title("pcolormesh") 
ax3.set_title("contourf") 
ax4.set_title("scatter") 
plt.tight_layout() 
fig.colorbar(im, ax=fig.axes, pad=0.05) 
plt.show()