How to get contours of TF2 and TH2 draw in TGraph

Continuing the conversation in link bellow

As suggested I am trying to get each contour in TGraph. But I don’t know whether the contours are stored in TGraph or not. When I draw the graph the canvas comes out as empty. The code is given bellow.

void test_contour(){
   auto c1 = new TCanvas("c1","c1",600,400);
   auto hcont4 = new TH2F("hcont4","Option CONT4Z example ",40,-4,4,40,-20,20);
   float px, py;
   for (Int_t i = 0; i < 25000; i++) {
      gRandom->Rannor(px,py);
      hcont4->Fill(px-1,5*py);
      hcont4->Fill(2+0.5*px,2*py-10.,0.1);
   }

 Double_t contours[6];
   contours[0] = 20;
   contours[1] = 40;
   contours[2] = 60;
   contours[3] =  80;
   contours[4] =  100;
   contours[5] =  120;
   hcont4->SetContour(6, contours);

   hcont4->Draw("CONT LIST");
   c1->Update();

   TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
   Int_t ncontours     = conts->GetSize();
    TList *list = NULL;
for(int i=0;i<ncontours; i++)
        {
        list= (TList*)conts->At(i);
        }
        cout<<"ncontours=    "<<ncontours<<endl;
   TGraph *gr1 = (TGraph*)list->First();
   auto c1_graph = new TCanvas("c1_graph","c1_graph",600,400);
   gr1->Draw("C");
   c1_graph->Update();
}


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Do:

   gr1->Draw("AL");

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.