【问题标题】:How to plot 3 columns and 2 rows of images with white spaces?如何用空白绘制 3 列和 2 行图像?
【发布时间】:2021-08-21 12:07:39
【问题描述】:

我想绘制 3 列和 2 行图像。下面是我绘制它们的代码,但有一个空格。如何绘制没有空白的图像?

fig, axes = plt.subplots(2, 3, figsize=(10,10))
for i in range(2):
    ax1, ax2, ax3 = axes[i]
    ax1.imshow(X[i])
    ax1.set_title('Noise Image')
    ax2.imshow(y[i])
    ax2.set_title('Actual Image')
    ax3.imshow(denoised_imgages[i])
    ax3.set_title('OutputImage')
plt.show()

以上代码输出的图片参考:

【问题讨论】:

  • 选择不同的无花果尺寸?
  • fig.subplots_adjust(wspace=0, hspace=0) 会去掉一些空白,但是因为 imshow 强制轴上的纵横比相等,除非你得到完全正确的图形纵横比,否则一些会保留

标签: python image matplotlib plot


【解决方案1】:

尝试使用subplots_adjust()

一个简单的例子:-

fig, axes = plt.subplots(2, 3, figsize=(10,10))
plt.subplots_adjust(wspace=0, hspace=0)
for i in range(2):
    ax1, ax2, ax3 = axes[i]
    ax1.imshow(X[i])
    ax1.axis('off') # for removing axis
    ax2.axis('off')
    ax3.axis('off')
    ax1.set_title('Noise Image')
    ax2.imshow(y[i])
    ax2.set_title('Actual Image')
    ax3.imshow(denoised_imgages[i])
    ax3.set_title('OutputImage')
plt.show()

subplots_adjust 的用法:-

subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)

【讨论】:

    猜你喜欢
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-22
    相关资源
    最近更新 更多