2

I've had problems with code running speed slowing down. This time, it is simple enough to be put up for investiagtion. I'm just displaying a bunch of images.

images = np.random.rand(200, 150, 150)
for index, animage in enumerate(images):
    plt.imshow(animage)
    plt.title(str(index))
    plt.pause(0.05)

It starts very fast, and then is slows to crawling speed. Why is that?

PS: I do realize that animation is the correct way of doing it.

Alex Deft
  • 2,531
  • 1
  • 19
  • 34
  • It is likely because matplotlib is having to render progressively more and more images as time goes on – Recessive Jul 12 '19 at 04:46
  • @Recessive But I've basically set the pace of redering, didn't I? – Alex Deft Jul 12 '19 at 04:46
  • 1
    Does matplotlib only show one image at a time? Or does it make multiple windows? If it is only showing one image at a time, my guess would be that it is still doing something with the previously shown images in the background. If you are constantly changing the image, I think and animation might be a better bet, or using a figure so you can perform`.flush_events()` – Recessive Jul 12 '19 at 04:52
  • One image at a time. Basically a primitive way of rendering. I used your flush_events() method. Same same. I do realize that animation is the right way to do it. – Alex Deft Jul 12 '19 at 05:00
  • 1
    You never clean up your old plots. – MisterMiyagi Jul 12 '19 at 05:07
  • @MisterMiyagi How do I do that? – Alex Deft Jul 12 '19 at 05:07

0 Answers0