I want to display MNIST images as a composite image using matplotlib. Right now it is displaying the individual images on a horizontal plane (1 row, x columns) but there is whitespace between each image.
How can I bring the images right next to each other (removing the vertical whitespace between each MNIST image) so it looks like 1 single image?
Here is the relevant part of my code:
for x in range(5):
digit = train_images[x]
plt.box(False)
plt.subplot(1, 5, x+1)
plt.imshow(digit)
plt.axis('off')
plt.grid(b=None)
#plt.title('50419 -- my Name', loc='center')
plt.show()
This is what the current output looks like:
Maybe you could try with this 'fig' method:
fig.subplots_adjust(wspace = 0)
First you would have to create a fig and an axis:
fig, ax = plt.subplots(1, 5)
Actually, I was able to fix it with just a single line of code:
plt.tight_layout(pad=0.00)
This brought the images right next to each other.
Thanks JUSTGETTINGSTARTED
plt.tight_layout(pad=0.00)
works for me too
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.