##// END OF EJS Templates
Describe usermod changes in What's New docs.
Describe usermod changes in What's New docs.

File last commit:

r5279:4d707b82
r5464:7a27135a
Show More
clear_output.ipynb
156 lines | 61.3 KiB | text/plain | TextLexer

A demonstration of the ability to clear the output of a cell during execution.

InĀ [8]:
from IPython.core.display import clear_output, display
InĀ [4]:
import time

First we show how this works with display:

InĀ [20]:
for i in range(10):
    clear_output()
    print "Time step: %i" % i
    time.sleep(0.5)
Time step: 9

Next, we show that clear_output can also be used to create a primitive form of animation using matplotlib:

InĀ [18]:
for i in range(10):
    figure()
    plot(rand(100))
    clear_output()
    show()
    time.sleep(0.25)
No description has been provided for this image

And we can even selectively clear only a subset of stdout/stderr/other display such as figures (all are cleared by default).

InĀ [19]:
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)
Time step: 0
Time step: 1
Time step: 2
Time step: 3
No description has been provided for this image