0

I created a for-loop that generates a new image every increment. I'm just wondering how I could adjust the images within the loop. Right now, it is just plotting images in a single column. How can I adjust the images in the for-loop so it shows two columns?

for i in range(10):
            a = (0 + i, 0, 0, 0)
            plt.imshow(a)
            plt.title("Hi " + str(i))
kdf
  • 358
  • 4
  • 16

1 Answers1

0

Using matplotlib.pyplot.subplots you can create a single figure containing a 2D grid of smaller plots (or axes, as they are called in Matplotlib), next you can iterate on the 2D structure as usual (just remember to call the .tight_layout method to narrow the plot frames and have enough space for the labels).

import matplotlib.pyplot as plt                                                   

fig, grid = plt.subplots(5,2)                                                     
count = 1                                                                         

for row in grid: 
    for ax in row: 
        ax.plot((0,1),(count,count)) 
        count += 1 

fig.tight_layout()                                                                

enter image description here

gboffi
  • 22,939
  • 8
  • 54
  • 85