Simple TH2 clipping question

Is it possible to draw a TEllipse (or other object based on polylines) on a TH2 and have it clipped to the axis box?

For example if one runs:

TH2D *h = new TH2D("test","test",10,0,1,10,0,1);
TEllipse *el = new TEllipse(0.5,0,0.2);

The full ellipse is drawn, which extends outside the axis (it’s clipped at the pad border instead of the axis border). I’m sure there must be simple way to avoid this (clearly there’s code to do clipping of polylines in TPad), but I can’t seem to figure out how to use it properly for the axis box.


I suggest the following:

{ TCanvas *c1 = new TCanvas("c1"); TH2D *h = new TH2D("test","test",10,0,1,10,0,1); TEllipse *el = new TEllipse(0.5,0,0.2); TExec *exec1 = new TExec("exec1","gPad->SetBit(TGraph::kClipFrame);"); TExec *exec2 = new TExec("exec2","gPad->ResetBit(TGraph::kClipFrame);"); h->GetListOfFunctions()->Add(exec1); h->GetListOfFunctions()->Add(el); h->GetListOfFunctions()->Add(exec2); h->Draw(); }