Skip to content

clear_output from code #432

@zivy

Description

@zivy

This is repeat of a question I posted on stack-overflow (no response there so hopefully someone here can help):

I am trying to incrementally plot a graph, animating the progress of an image registration process. In a Python notebook this is done by repeatedly plotting and clearing the output. A MWE:

import matplotlib.pyplot as plt
%matplotlib inline
import time

from IPython.display import clear_output

values = (1.23, 4.5, 1.23, 4.5)
for i in range(1,5):
    clear_output(wait=True)
    plt.plot(0, values[0], 'b*')
    plt.plot(values[0:i], 'r')
    time.sleep(0.5)
    plt.show()

The equivalent in R (missing the clear-output):

values <- c(1.23, 4.5, 1.23, 4.5)

for (i in 1:4) {
  # clear output
  plot(values[1:i], type="l", las=1, col="red")
  points(1, values[1], col="blue", pch=18)
  Sys.sleep(0.5)
}

In practice the plots will not be created in a for-loop, these are callbacks from the computationally intensive image registration. I am using the for loop as the MWE.

Is it possible to programmatically clear the output using the ir kernel? If yes, how? If not, any suggestions on creating animations in the notebook. This needs to be an online solution - saving images and creating an animated gif is not relevant for this purpose.

For those curious about the specific goal, this is part of our development of Jupyter SimpleITK notebooks.

Any advice is much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions