# How to save two subplots in one figure?

I can make one 64x64 figure using subplot
but can’t make two figure in one like upper image…
How can I do this in one figure?

And this is my fool code

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

Thank you.

`plt.subplots` will return the figure handle and an axis array.
This code should work:

``````x = np.random.randn(64, 64, 3)

f, axarr = plt.subplots(1, 2)
axarr[0].imshow(x)
axarr[1].imshow(x)
``````

Otherwise, this modified version of your code should do the work :

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

Hi , sorry I am using this code how I can adjust the space between rows and columns? and write title for each row?

``````            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')
``````

`matplotlib.pyplot.subplots_adjust` could probably be used.
Note that you would get faster and better answers on e.g. StackOverflow for non-PyTorch-specific questions.