numpy.ndarray 对象没有属性 imshow

我正在尝试将 python 与 jupyter notebook 结合使用,想出一个方案,您可以握住智能灯泡并通过漫反射从手中获取信息。我已经设法完成所有这些工作,并且所有这些都保存在一个变量 PIX 中:


PIX = np.array(pictures)

print(PIX.shape)

这会像预期的那样输出一个 (81,480,640,3)(81 表示转换为 RGB 的可见光谱,以便灯得到它)。


但是,我现在想可视化数据,我认为 imshow 是完美的实现。我更改了一些变量,使脚本如下所示:


# Plot the images on a subplots array 

fig, axes = 

plt.subplots(int(PIX.shape[0]/9),int(PIX.shape[0]/9))


for i, ax in enumerate(axes):

    axes[i].imshow(PIX[i,:,:,0], interpolation='none')

# Render the figure

plt.show()

同样,这非常简单。但是,我收到错误:


AttributeError                            Traceback (most recent call last)

<ipython-input-20-a7bb604d1828> in <module>

      3 

      4 for i, ax in enumerate(axes):

----> 5     axes[i].imshow(PIX[i,:,:,0], interpolation='none')

      6 # Render the figure

      7 plt.show()


AttributeError: 'numpy.ndarray' object has no attribute 'imshow' 

我尝试使用 matplotlib修复'numpy.ndarray' object has no attribute 'imshow'和'numpy.ndarray' object has no attribute 'show' ,他们似乎有类似的问题。但是,这些修复似乎都不适用于我的情况。


任何帮助,将不胜感激!


慕盖茨4494581
浏览 530回答 1
1回答

茅侃侃

axes是一个 2D ndarray 所以你必须使用两个索引。或者,您可以更换for&nbsp;i,&nbsp;ax&nbsp;in&nbsp;enumerate(axes)和for&nbsp;i,&nbsp;ax&nbsp;in&nbsp;enumerate(axes.ravel())
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python