1

Is there any way to create the plot in steps, showing the progress each time plt.show method is called? Even if a play around with plt.show(block=False) or plt.show(block=True) not able to make it work.

import matplotlib.pyplot as plt

xvals = [i for i in range(0, 10)]
yvals1 = [i**2 for i in range(0, 10)]
yvals2 = [i**3 for i in range(0, 10)]
yvals3 = [i**4 for i in range(0, 10)]

f, ax = plt.subplots(1)
ax.plot(xvals, yvals1)

plt.show(block=False)
raw_input("Program paused. Press Enter to continue...")

ax.plot(xvals, yvals2)
plt.show() # Need to close the window to go ahead.
raw_input("Program paused. Press Enter to continue...")

ax.plot(xvals, yvals3)
plt.show(block=False)
raw_input("Program paused. Press Enter to continue...")

I am running matplotlib==2.0.0 in a virtualenv with Pydev. Any idea?

fara
  • 21
  • 3
  • 1
    Maybe the information in [this answer](http://stackoverflow.com/a/12685979/3005167) can help you. (i.e. try calling `plt.ion()` in the beginning of your script). – MB-F Feb 13 '17 at 14:44
  • Apart from adding plt.ion() , if I add a plt.pause(0.0001) after each plt.show() command, it makes the trick. But I don't know if there is any other better way. – fara Feb 15 '17 at 14:14
  • 1
    There is another way: [animation](http://matplotlib.org/1.4.1/examples/animation/index.html) Which way is better depends on your use case. Animation is more complex but may be more robust. For "production" code I would probably do this. If you only want to visualize steps of your code as it runs during development/debugging "quick and dirty" beats "robust and elaborate" in my opinion :) – MB-F Feb 15 '17 at 14:40

1 Answers1

0

You should be able to do it if you release the related event loop to allow the UI to refresh to the user (i.e.: on qt you'd need to get the event loop and call QEventLoop::processEvents for it to appear).

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78