Show More
@@ -21,7 +21,7 | |||
|
21 | 21 | "source": [ |
|
22 | 22 | "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 can clear the whole output area, not just a single line.\n", |
|
23 | 23 | "\n", |
|
24 | "To clear output in the Notebook you can use the `clear_output` function." | |
|
24 | "To clear output in the Notebook you can use the `clear_output()` function. If you are clearing the output every frame of an animation, calling `clear_output()` will create noticeable flickering. You can use `clear_output(wait=True)` to add the *clear_output* call to a queue. When data becomes available to replace the existing output, the *clear_output* will be called immediately before the new data is added. This avoids the flickering by not rendering the cleared output to the screen." | |
|
25 | 25 | ] |
|
26 | 26 | }, |
|
27 | 27 | { |
@@ -58,7 +58,7 | |||
|
58 | 58 | "from IPython.display import display, clear_output\n", |
|
59 | 59 | "for i in range(10):\n", |
|
60 | 60 | " time.sleep(0.25)\n", |
|
61 | " clear_output()\n", | |
|
61 | " clear_output(wait=True)\n", | |
|
62 | 62 | " print(i)\n", |
|
63 | 63 | " sys.stdout.flush()" |
|
64 | 64 | ], |
@@ -166,7 +166,7 | |||
|
166 | 166 | "for n in range(1,10):\n", |
|
167 | 167 | " time.sleep(1)\n", |
|
168 | 168 | " ax.plot(x, jn(x,n))\n", |
|
169 | " clear_output()\n", | |
|
169 | " clear_output(wait=True)\n", | |
|
170 | 170 | " display(f)\n", |
|
171 | 171 | "\n", |
|
172 | 172 | "# close the figure at the end, so we don't get a duplicate\n", |
General Comments 0
You need to be logged in to leave comments.
Login now