【问题标题】:How to plot 3d array in gray scale in matplotlib如何在 matplotlib 中以灰度绘制 3d 数组
【发布时间】:2019-05-09 02:35:16
【问题描述】:

想要在灰度图像中绘制一个数组。这是我的数组:

[[[ 0.27543858  0.30173767 -0.0101363   0.30631673  0.08575112
    0.02205707 -0.15502007  0.11055402 -0.11761152]
  [ 0.23695524  0.19820367 -0.08758862  0.02446048  0.29235974
   -0.11381532 -0.00426369  0.15231356 -0.24601455]]]

它的维度是 (1, 2, 9)。它应该产生两个图像,每个图像有 9 个值。 到目前为止我已经尝试过了:

col_size = 1
row_size = 2
index = 0
fig, ax = plt.subplots(row_size, col_size, figsize=(12,8))
for row in range(0,row_size): 
  for col in range(0,col_size):
    ax[row][col].imshow(result_array[:,:,index],cmap='gray')
    index += 1

plt.show()

【问题讨论】:

    标签: python-2.7 matplotlib


    【解决方案1】:

    答案如下:

    result_array=result_array.reshape(2,3,3)
    print(result_array)
    print(result_array.shape)
    
    col_size = 2
    row_size = 1
    filter_index = 0
    fig, ax = plt.subplots(row_size, col_size, figsize=(12,8),  squeeze=False)
    for row in range(0,row_size): 
      for col in range(0,col_size):
        ax[row][col].imshow(result_array[filter_index,:,:],cmap='gray')
        filter_index += 1
    
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2021-03-06
      • 1970-01-01
      • 2014-10-06
      • 2012-06-01
      • 1970-01-01
      • 2015-04-22
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多