A demonstration of the ability to clear the output of a cell during execution.
from IPython.core.display import clear_output, display
import time
First we show how this works with display
:
for i in range(10):
clear_output()
print "Time step: %i" % i
time.sleep(0.5)
Next, we show that clear_output
can also be used to create a primitive form of animation using
matplotlib:
for i in range(10):
figure()
plot(rand(100))
clear_output()
show()
time.sleep(0.25)
And we can even selectively clear only a subset of stdout/stderr/other display such as figures (all are cleared by default).
for i in range(4):
print "Time step: %i" % i
figure()
plot(rand(100))
# clear plots, but not stdout:
clear_output(stdout=False)
show()
time.sleep(0.25)