[Python] Plotting images side by side using matplotlib

Discussão em 'Python' iniciado por Stack, Julho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I was wondering how I am able to plot images side by side using matplotlib for example something like this:

    [​IMG]

    The closest I got is this:

    [​IMG]

    This was produced by using this code:

    f, axarr = plt.subplots(2,2)
    axarr[0,0] = plt.imshow(image_datas[0])
    axarr[0,1] = plt.imshow(image_datas[1])
    axarr[1,0] = plt.imshow(image_datas[2])
    axarr[1,1] = plt.imshow(image_datas[3])


    But I can't seem to get the other images to show. I'm thinking that there must be a better way to do this as I would imagine trying to manage the indexes would be a pain. I have looked through the documentation although I have a feeling I may be look at the wrong one. Would anyone be able to provide me with an example or point me in the right direction?

    EDIT:

    See the answer from @duhaime if you want a function to automatically determine the grid size.

    Continue reading...

Compartilhe esta Página