Remove an object from canvas

How can I remove a TH1D* from a Canvas, without actually deleting it because I will be populating it interactively via GUI.

h->Clear(); // didn’t seem to work.

Not sure how I can accomplish this. Any help appreciated.

c->GetListOfPrimitives()->Remove(h); c->Modified();

[quote=“Pepe Le Pew”]Try:
c->GetListOfPrimitives()->Remove(h); c->Modified();[/quote]

This method works great. I have one more issue now. When I try to draw it again, it doesn’t draw the axis, just the points with all the style, color properties intact. Any ideas how I can resolve it ?

Axes disappeared? … maybe what you really wanted was:

[quote=“Pepe Le Pew”]Axes disappeared? … maybe what you really wanted was:

Clearing up works actually, but the issue is, when I remove the last histogram, it takes away everything with it i.e. the axes too.

Usually, the first drawn histogram creates and “owns” axes. So, if you remove it, also axes are gone.
You could try to “DrawFrame” first.
Or, try something like this in the beginning:
TH1 *haxes = h->DrawCopy(“AXIS”); // draw only “standalone” axes
haxes->SetStats(kFALSE); c->Modified(); // remove its "statistics box"
h->Draw(“SAMES”); // draw the “contents” (and its “statistics box”)