how to remove “empty” space between subplots?

前端 未结 2 1083
生来不讨喜
生来不讨喜 2021-01-14 04:55

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:

2条回答
  •  生来不讨喜
    2021-01-14 05:26

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

    enter image description here

提交回复
热议问题