##// END OF EJS Templates
add IPython.utils.tz...
add IPython.utils.tz Basic support for tz-aware UTC methods on date time objects. The raw `utcfoo` methods still produce naïve objects, so they are wrapped in a simple zero-offset tz-aware object. This allows jsonutil to publish the timezone info, eliminating the ambiguity of naïve timestamps (Firefox assumes local time, WebKit UTC).

File last commit:

r9455:89fe4319
r11144:e8549ce5
Show More
Animations Using clear_output.ipynb
200 lines | 53.2 KiB | text/plain | TextLexer
/ examples / notebooks / Animations Using clear_output.ipynb

Simple animations Using clear_output

Sometimes you want to clear the output area in the middle of a calculation. This can be useful for doing simple animations. In terminals, there is the carriage-return ('\r') for overwriting a single line, but the notebook frontend does not support this behavior.

To clear output in the Notebook you can use the clear_output function.

Simple example

Here we show our progress iterating through a list:

In [1]:
import sys
import time
In [2]:
from IPython.display import clear_output
for i in range(10):
    time.sleep(0.25)
    clear_output()
    print(i)
    sys.stdout.flush()
9

AsyncResult.wait_interactive

The AsyncResult object has a special wait_interactive() method, which prints its progress interactively, so you can watch as your parallel computation completes.

This example assumes you have an IPython cluster running, which you can start from the cluster panel

In [3]:
from IPython import parallel
rc = parallel.Client()
view = rc.load_balanced_view()

amr = view.map_async(time.sleep, [0.5]*100)

amr.wait_interactive()
 100/100 tasks finished after   30 s
done

Matplotlib example

You can also use clear_output() to clear figures and plots.

In [4]:
%pylab inline
Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.kernel.zmq.pylab.backend_inline].
For more information, type 'help(pylab)'.
In [5]:
from scipy.special import jn
x = np.linspace(0,5)
f, ax = plt.subplots()
ax.set_title("Bessel functions")

for n in range(1,10):
    time.sleep(1)
    ax.plot(x, jn(x,n))
    clear_output()
    display(f)

# close the figure at the end, so we don't get a duplicate
# of the last plot
plt.close()
No description has been provided for this image