python图像加网格,python – matplotlib中没有填充的图像网格

该博客探讨了如何在matplotlib中使用gridspec创建图像网格,并消除行之间的填充,同时尝试增加子图的尺寸。作者通过导入相关库,设置GridSpec参数,以及调整子图间距来实现这一目标。然而,他们遇到了问题,即无法完全移除行间隔并增大子图的尺寸。博客最后展示了代码示例,但没有给出最终解决方案。
摘要由CSDN通过智能技术生成

我正在尝试使用gridspec在matplotlib中制作一个图像网格.问题是,我似乎无法摆脱行之间的填充.

这是我对解决方案的尝试.

import matplotlib.pyplot as plt

from mpl_toolkits.axes_grid1 import ImageGrid

import numpy as np

from os import listdir

from os import chdir

from PIL import Image

import matplotlib.gridspec as gridspec

chdir('/home/matthew/Dropbox/Work/writing/'+

'paper_preperation/jump_figs')

files = listdir('/home/matthew/Dropbox/Work/writing/'+

'paper_preperation/jump_figs')

images = [Image.open(f) for f in files]

"""

fig = plt.figure()

grid = ImageGrid(fig, 111, # similar to subplot(111)

nrows_ncols = (2, 5), # creates 2x2 grid of axes

axes_pad=0.1, # pad between axes in inch.

)

"""

num_rows = 2

num_cols = 5

fig = plt.figure()

gs = gridspec.GridSpec(num_rows, num_cols, wspace=0.0)

ax = [plt.subplot(gs[i]) for i in range(num_rows*num_cols)]

gs.update(hspace=0)

#gs.tight_layout(fig, h_pad=0,w_pad=0)

for i,im in enumerate(images):

ax[i].imshow(im)

ax[i].axis('off')

#ax_grid[i/num_cols,i-(i/num_cols)*num_cols].imshow(im) # The AxesGrid object work as a list of axes.

#ax_grid[i/num_cols,i-(i/num_cols)*num_cols].axis('off')

"""

all_axes = fig.get_axes()

for ax in all_axes:

for sp in ax.spines.values():

sp.set_visible(False)

if ax.is_first_row():

ax.spines['top'].set_visible(True)

if ax.is_last_row():

ax.spines['bottom'].set_visible(True)

if ax.is_first_col():

ax.spines['left'].set_visible(True)

if ax.is_last_col():

ax.spines['right'].set_visible(True)

"""

plt.show()

还有谁知道如何使每个子图更大?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值