如何删除“空"子图之间的空间? [英] how to remove "empty" space between subplots?

查看:66
本文介绍了如何删除“空"子图之间的空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个总共有 68 个子图的图形,并想删除它们之间的空白区域.这是我所拥有的:

I'm making a figure with a total of 68 subplots and want to remove the empty space between them all. Here's what I have:

.

我该怎么做?

使用 plt.tight_layout() 会使情况更糟:

using plt.tight_layout() makes it even worse:

这是我的代码:

for j in range(0,len(sort_yf)):
for i in range(0,len(yf)):
    if yf[i]==sort_yf[j]:
        sort_ID=np.append(sort_ID,'output/'+ID[i]+'.png')
for i in range (1,69):
    plt.subplot(17,4,i,aspect='equal')
    plots=img.imread(sort_ID[i])
    plt.imshow(plots)
    plt.axis('off')
plt.show()

推荐答案

您是否尝试过紧凑的布局功能?

Have you tried the tight layout functionality?

plt.tight_layout()

另见此处

编辑:或者,您可以使用 gridspec:

EDIT: Alternatively, you can use gridspec:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
images = [np.random.rand(40, 40) for x in range(68)]
gs = mpl.gridspec.GridSpec(17, 4)
gs.update(wspace=0.1, hspace=0.1, left=0.1, right=0.4, bottom=0.1, top=0.9) 
for i in range(68):
    plt.subplot(gs[i])
    plt.imshow(images[i])
    plt.axis('off')
plt.show()

这篇关于如何删除“空"子图之间的空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆