gpt4 book ai didi

python - 使用 matplotlib 并排绘制图像

转载 作者:IT老高 更新时间:2023-10-28 22:20:23 31 4
gpt4 key购买 nike

我想知道如何使用 matplotlib 并排绘制图像,例如:

enter image description here

我得到的最接近的是:

enter image description here

这是使用以下代码生成的:

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

但我似乎无法显示其他图像。我认为必须有更好的方法来做到这一点,因为我想尝试管理索引会很痛苦。我浏览了documentation虽然我有一种感觉,我可能看错了。谁能给我一个例子或指出我正确的方向?

编辑:

answer来自 @duhaime如果你想要一个函数来自动确定网格大小。

最佳答案

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

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

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) 接口(interface)相同的方法。例如。如果 ax 是您的子图轴之一,则要绘制法线图,您将使用 ax.plot(..) 而不是 plt.plot() 。这实际上可以在 the page you link to 的源代码中找到。 .

关于python - 使用 matplotlib 并排绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41793931/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com