Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make matplotlib imshow blocking print() in a for loop

In ipython notebook, I am using matplotlib.pyplot imshow in a for loop like this:

for i in range(3):
    plt.figure()
    plt.imshow(I[i])
    print("some explanation for image " + str(i))

Basically I hope to show each image followed by a print out sentence. But what I get is 3 sentences are printed out together, then followed with 3 images.

I tried to use time.sleep(1) before print() but does not work. Any idea to get the outputs of plt.imshow() and print() interleaving with each other?

like image 744
wakeupbuddy Avatar asked Mar 31 '26 11:03

wakeupbuddy


1 Answers

Not what you asked for, but it will serve the same purpose:

for i in range(3):
    plt.figure()
    plt.imshow(I[i])
    plt.title("some explanation for image " + str(i))

Jupyter notebook showing images with titles

like image 55
Neapolitan Avatar answered Apr 02 '26 23:04

Neapolitan