4

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?

2
  • You need to use the extent kwarg to move them from overlapping. Commented Jan 2, 2017 at 19:56
  • @tacaswell Thanks! I am new to Python , an example of how I might do this will be nice Commented Jan 2, 2017 at 20:02

2 Answers 2

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This works ! but the images are really small . The original image is 224*224 quite big. How do i increase the image size in the plot ?
You can specify a figure size. See my updated answer.
1

this function creates subplot for each image:
the img has shape of (n,height,width,channel)

import numpy as np
def picshow(img):
    num = len(img)
    ax = np.ceil(np.sqrt(num)) 
    ay = np.rint(np.sqrt(num)) 
    fig =plt.figure()
    for i in range(1,num+1):
        sub = fig.add_subplot(ax,ay,i)
        sub.set_title("titre",i)
        sub.axis('off')
        sub.imshow(data[i-1])
    plt.show()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.