且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 matplotlib 并排绘制图像

更新时间:2023-11-10 12:52:46

您面临的问题是您尝试分配 imshow(这是一个matplotlib.image.AxesImage 到现有的轴对象.

The problem you face is that you try to assign the return of imshow (which is an matplotlib.image.AxesImage to an existing axes object.

axarr 中将图像数据绘制到不同轴的正确方法是

The correct way of plotting image data to the different axes in axarr would be

f, axarr = plt.subplots(2,2)
axarr[0,0].imshow(image_datas[0])
axarr[0,1].imshow(image_datas[1])
axarr[1,0].imshow(image_datas[2])
axarr[1,1].imshow(image_datas[3])

所有子图的概念都相同,并且在大多数情况下,轴实例提供与 pyplot (plt) 接口相同的方法.例如.如果 ax 是您的子图轴之一,要绘制法线图,您将使用 ax.plot(..) 而不是 plt.plot().实际上,可以在您链接到的页面的源代码中找到它们.

The concept is the same for all subplots, and in most cases the axes instance provide the same methods than the pyplot (plt) interface. E.g. if ax is one of your subplot axes, for plotting a normal line plot you'd use ax.plot(..) instead of plt.plot(). This can actually be found exactly in the source from the page you link to.