Redrawing TCanvas in Jupyter notebook

Hello,

is it possible to redraw TCanvas in the same Jupyter cell (replace the previously drawn plot with the new one)?

The following standalone example demonstrates my goal:

import ROOT
import ipywidgets as widgets
 
ROOT.gStyle.SetOptStat(0)

slider = widgets.IntSlider(description='Bins', min=3, max=100, step=1, value=30, layout=widgets.Layout(width='50%'))

c1 = ROOT.TCanvas("c1", "Example")
c1.Draw()
    
@widgets.interact(bins=slider)
def plot_interactively(bins: int):
    # I thought this would delete the objects inside the canvas, but no
    c1.Clear()
    h1 = ROOT.TH1F("h1", "h1", bins, 0, 5)
    h1.Fill(1)
    h1.Fill(2)
    h1.Fill(3)
    h1.Fill(1)
    h1.Fill(2)
    h1.Fill(1)
    h1.DrawClone()
   # c1.Draw() # This command will display the updated canvas, but as new. The old one stays there as well.

With each change, I would like to replace the existing plot with a new one.

Thank you for your help.

Regards,
Ladislav

Maybe @linev can help with this.

Hi Ladislav,

Unfortunately it is impossible to update canvas drawing.
Only new drawing with c1.Draw() can be done.

Regards,
Sergey

Hi Sergey,

thank you for the information.

Do you think it would be possible to remove the existing plot from the output of the current cell before calling c1.Draw() again?

Many thanks,
Ladislav

Hi Ladislav,

Currently it is not possible.

I am trying to implement new method of canvas display in the Jupyter.
Maybe update of the existing drawing can be implemented too.
But this will take time and will not be part of next ROOT release.

Regards,
Sergey