how to remove “empty” space between subplots?

笑着哭i 提交于 2019-12-01 08:44:49

Have you tried the tight layout functionality?

plt.tight_layout()

See also HERE

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()

Adjust the whitespace around the subplots with:

plt.subplots_adjust(wspace=0.01,hspace=0.01)

In my example I just modified wspace and hspace. You can also adapt the positions. Consider the documentation.

You could also modify the GridSpec Layout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!