Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show multiple image in matplotlib from numpy array

I have an array with the shape (1, 64, 224, 224). 64 Single channel images of size 224*224. When I do this:

plt.imshow(output_image[0,1,:,:], interpolation='nearest')

The image is displayed properly.

But when I do:

for i in range(64):
    plt.imshow(output_image[0,i,:,:], interpolation='nearest')

I see only 1 image as result even though there are 64 images.

How can I get a line of 64 images? What am I doing wrong?

like image 258
Abhik Avatar asked Dec 24 '22 22:12

Abhik


1 Answers

You can create a new subplot for each image:

fig = plt.figure(figsize=(50, 50))  # width, height in inches

for i in range(64):
    sub = fig.add_subplot(64, 1, i + 1)
    sub.imshow(output_image[0,i,:,:], interpolation='nearest')

This will put all 64 images in one column. Change to:

sub = fig.add_subplot(8, 8, i + 1)

for eight columns and eight rows.

like image 100
Mike Müller Avatar answered Jan 07 '23 01:01

Mike Müller