I wanna display in a list of lists the images inside it using matplotlib. So for example I wanna have in the first row, the images of the first list, the second row, the images of the second list and so on. I tried this, but I obtain the images in each row, maybe because it will call over and over again subplot. How can I fix it?
list_plot = [['query/obj100__40.png', 'model/obj100__0.png', 'model/obj19__0.png', 'model/obj23__0.png', 'model/obj33__0.png', 'model/obj69__0.png'], ['query/obj12__40.png', 'model/obj12__0.png', 'model/obj80__0.png', 'model/obj53__0.png', 'model/obj51__0.png', 'model/obj41__0.png'], ['query/obj17__40.png', 'model/obj17__0.png', 'model/obj15__0.png', 'model/obj91__0.png', 'model/obj3__0.png', 'model/obj84__0.png']]
index_plot=0
for query in list_plot:
for qm_images in query:
plt.subplot(3,5,index_plot 1)
plt.imshow(np.array(Image.open(qm_images)))
plt.show()
index_plot = 1
CodePudding user response:
Instead of creating many subplots initially create a nested list of subplots
with plt.subplots()
, call imshow on each axis
import matplotlib.pyplot as plt
fig, axs = plt.subplots(3, 6)
for i, query in enumerate(list_plot):
for j, qm_images in enumerate(query:
axs[i][j].imshow(np.array(Image.open(qm_images)))
plt.show()