2

I have some jpegs in a directory. I want to display them in a window in rows and columns. For example if I have 10 pictures, I want to display them a 2 rows by 5 columns table.
There is a subplot(m, n, k) command in MATLAB and Octave. How can I do similar thing in python?

I have tried pillow with PIL.Image and show() method but it is very limited and displays only 1 image.

1- How to do this natively (not in browser)?
2- How to do this using matplotlib?
3- How to do this in browser using Jupyter?

8
  • @DizietAsahi think he wants the same functionality in matplotlib. Commented Oct 1, 2018 at 14:08
  • See matplotlib.org/users/image_tutorial.html and matplotlib.org/gallery/subplots_axes_and_figures/… Commented Oct 1, 2018 at 14:12
  • @Andrei you're right, I did not look closely at the post I was linking, I assumed it was matplotlib code Commented Oct 1, 2018 at 14:13
  • @DizietAsahi Can matplotlib display local jpeg also? Commented Oct 1, 2018 at 14:15
  • 1
    Those are really three questions and each has its own answer. (1) concatenate the images with Pillow. (2) use subplots in matplotlib and imshow the images (3) Create a HTML table with the images in it. Those are orthorgonal solutions and while I might help with any of them, writing up a complete answer with code for all three of them is above my current bandwidth. Plus, each of those is probably been answered already somewhere. Commented Oct 1, 2018 at 14:20

1 Answer 1

10
import matplotlib.pyplot as plt
from PIL import Image

fig,ax = plt.subplots(2,5)

filenames=['\path\to\img\img_{}.jpg'.format(i) for i in range(10)] #or glob or any other way to describe filenames
for i in range(10):
    with open(filenames[i],'rb') as f:
        image=Image.open(f)
        ax[i%2][i//2].imshow(image)
fig.show()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.