How to save two subplots in one figure?

username: wonchulSon
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/3/e38d83453d367a191bb89d973b021d96f43b01b9.png" data-download-href="https://discuss.pytorch.org/uploads/default/e38d83453d367a191bb89d973b021d96f43b01b9" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/3/e38d83453d367a191bb89d973b021d96f43b01b9.png" alt="image" data-base62-sha1="wt1zGhfriYYtd6fggLtZke6duPL" width="690" height="336" data-dominant-color="FAFAFA"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1077×525 5.23 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>I can make one 64x64 figure using subplot<br>
but can’t make two figure in one like upper image…<br>
How can I do this in one figure?</p>
<p>And this is my fool code</p>
<pre><code class="lang-auto">def visfeaturemap(feature_maps, filename='default.png', save=False):
    # plot all 64 maps in an 8x8 squares
    square = 8
    ix = 1
    for _ in range(square):
        for _ in range(square):
            # specify subplot and turn of axis
            ax = plt.subplot(square, square, ix)
            ax.set_xticks([])
            ax.set_yticks([])
            # plot filter channel in grayscale
            plt.title(filename)
            plt.imshow(feature_maps[0, ix - 1, :, :].cpu().numpy())
            ix += 1

    plt.title(filename)
    plt.show()

    if save:
        plt.savefig(filename)
</code></pre>
<p>Thank you.</p>

username: ptrblck
cooked: <p><code>plt.subplots</code> will return the figure handle and an axis array.<br>
This code should work:</p>
<pre><code class="lang-python">x = np.random.randn(64, 64, 3)

f, axarr = plt.subplots(1, 2)
axarr[0].imshow(x)
axarr[1].imshow(x)
</code></pre>

username: phan_phan
cooked: <p>Otherwise, this modified version of your code should do the work :</p>
<pre><code class="lang-auto">def visfeaturemap(feature_maps, filename='default.png', save=False):
    # plot all 128 maps in two 8x8 squares
    square = 8
    for ix in range(square):
        for jx in range(square):
            # plot features_0 on the left
            # specify subplot and turn off axis
            ax = plt.subplot(square, 1+2*square, 1 + jx + (1+2*square)*ix)
            ax.set_xticks([])
            ax.set_yticks([])
            # plot filter channel in grayscale
            plt.imshow(feature_maps[0, ix].cpu().numpy())

            # plot features_1 on the right
            # specify subplot and turn off axis
            ax = plt.subplot(square, 1+2*square, 1 + jx + (1+2*square)*ix + (1+square))
            ax.set_xticks([])
            ax.set_yticks([])
            # plot filter channel in grayscale
            plt.imshow(feature_maps[1, ix].cpu().numpy())

    plt.title(filename)
    plt.show()

    if save:
        plt.savefig(filename)
</code></pre>

username: saba
cooked: <p>Hi , sorry I am using this code how I can adjust the space between rows and columns? and write title for each row?</p>
<pre><code class="lang-auto">            f, axarr = plt.subplots(7, 1)
            for jj in range(len(Listnum)):
                dd[0,jj1,0,0]=Listnum[jj]
                fake = netG(dd).squeeze(0).squeeze(0)
                plt.axis("off")????
                axarr[jj].imshow(fake.detach().numpy(),cmap='gist_gray',vmin=0,vmax=1)
            plt.savefig(os.path.join('/home/mom008/mmm/'+'/noise'+str(jj1)+'std='+str(jj))+'MAPcmbencode.jpg')
</code></pre>

username: ptrblck
cooked: <p><a href="https://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplots_adjust"><code>matplotlib.pyplot.subplots_adjust</code></a> could probably be used.<br>
Note that you would get faster and better answers on e.g. StackOverflow for non-PyTorch-specific questions.</p>