【问题标题】:matplotlib subplots - too many indices for array [duplicate]matplotlib subplots - 数组的索引太多[重复]
【发布时间】:2018-09-23 08:14:06
【问题描述】:

我对 plt.subplots 的工作方式感到很困惑

此 sn-p 有效 - 显示 2 x 2 布局

fig, axs = plt.subplots(2,2, figsize=(20, 10))
axs[0,0].set_title('Sobel')
axs[0,0].imshow(sobelx)
axs[0,1].set_title('S Channel')
axs[0,1].imshow(s_channel)
axs[1,0].set_title('Combined Binary')
axs[1,0].imshow(combined_binary)
axs[1,1].set_title('Color Stack')
axs[1,1].imshow(color_stack)

这个 sn-p 不起作用 - 1 by 2 布局

fig, axs = plt.subplots(1,2, figsize=(20, 10))
axs[0,0].set_title('Undistorted Image')
axs[0,0].imshow(undistort_img)
axs[0,1].set_title('Warped Image')
axs[0,1].imshow(warped_img)

IndexError: too many indices for array 出现此错误

当我打印轴形状时,第一种情况是(2, 2),第二种情况是(2,)。这是什么斧头?以及如何使第二段代码工作?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    您的第二个图本质上是一个一维数组。试试没有第二个坐标的代码。

    fig, axs = plt.subplots(1,2, figsize=(20, 10))
    axs[0].set_title('Undistorted Image')
    axs[0].imshow(undistort_img)
    axs[1].set_title('Warped Image')
    axs[1].imshow(warped_img)
    

    【讨论】:

      猜你喜欢
      • 2019-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-04
      • 1970-01-01
      • 1970-01-01
      • 2021-06-13
      • 2019-06-07
      相关资源
      最近更新 更多