2017-05-25 5 views
1

gridspec.GridSpecFromSubplotSpecmatplotlibとすると、形状(4,4,5,5)の配列を4つのサブプロット(幅と高さがそれぞれ4つの画像である小さな図形)にプロットすることができました。matplotlibを使って配列の形状(4,4,4,5,5)を2次元図にプロットする方法は?

形状(4,4,4,5,5)(各サブプロットは上記の図形です)で配列をどのようにプロットするのでしょうか?

次の図を参照してください。私はレベル1-3をプロットすることができましたが、レベル4をプロットする方法はわかりません。誰でも助けてくれますか?ありがとう enter image description here

+1

は、あなたがレベル1-プロットするために管理コードをすべて表示します3 –

+1

私がレベル3までできることを書くのを終えてくれてありがとう、私はその質問にも答えがあることを実感します。 – Daniel

答えて

1

私はそれがより単純なデータセットで動作するようにしたときに形状(4,4,5,5)で配列をプロットするためのコードを書くことをありがとう、私は(4,4,4、 5,5も)。以下は

形状と配列をプロットするコード(4,4,5,5)及び(4,4,4,5,5)

import matplotlib.pyplot as plt 
import matplotlib.gridspec as gridspec 
import math 
import numpy as np 

#### plot (4,4,5,5) 
data_4d = np.linspace(0, 1, 400).reshape((4,4,5,5)) 
num_out_img, num_inner_img, img_w, img_h = data_4d.shape 

fig = plt.figure(1, figsize=(6, 6)) 

outer_grid = math.ceil(math.sqrt(num_out_img)) 
inner_grid = math.ceil(math.sqrt(num_inner_img)) 

outer_frame = gridspec.GridSpec(outer_grid, outer_grid) 

for sub in range(num_out_img): 

    inner_frame = gridspec.GridSpecFromSubplotSpec(inner_grid, inner_grid, subplot_spec=outer_frame[sub], wspace=0.0, hspace=0.0) 

    for sub_sub in range(num_inner_img): 

     ax = plt.Subplot(fig, inner_frame[sub_sub]) 
     ax.imshow(data_4d[sub, sub_sub, :, :], cmap='gray') 
     fig.add_subplot(ax) 

plt.show() 

#### plot (4,4,4,5,5) 
data_5d = np.linspace(0, 1, 1600).reshape((4,4,4,5,5)) 
num_out_img, num_inner_img, num_deep_img, img_w, img_h = data_5d.shape 

fig = plt.figure(1, figsize=(6, 6)) 

outer_grid = math.ceil(math.sqrt(num_out_img)) 
inner_grid = math.ceil(math.sqrt(num_inner_img)) 
deep_grid = math.ceil(math.sqrt(num_deep_img)) 

outer_frame = gridspec.GridSpec(outer_grid, outer_grid) 

for sub in range(num_out_img): 

    inner_frame = gridspec.GridSpecFromSubplotSpec(inner_grid, inner_grid, subplot_spec=outer_frame[sub], wspace=0.0, hspace=0.0) 

    for sub_sub in range(num_inner_img): 

     deep_frame = gridspec.GridSpecFromSubplotSpec(deep_grid, deep_grid, subplot_spec=inner_frame[sub_sub], wspace=0.0, hspace=0.0) 

     for deep in range(num_deep_img): 

      ax = plt.Subplot(fig, deep_frame[deep]) 
      ax.imshow(data_5d[sub, sub_sub, deep, :, :], cmap='gray') 
      fig.add_subplot(ax) 

plt.show() 
関連する問題