Contours of TGraph2D

Hi all,

can anybody tell me how I can increase the number of contour colours for a TGraph2D??

TH1::SetContour(Int_t levels)

seems to be the right thing. But TGraph2D doesn’t inherit from TH1. From what I understood, calling TGraph2D::Draw(“cont”) creates a TH2D on the fly, but how can I set the contours there?


I am using v5.14

which option are you using to draw the TGraph2D ?


   TCanvas *c1 = new TCanvas("c1","Graph2D example",0,0,700,600);

   Double_t P = 5.;
   Int_t npx  = 20 ;
   Int_t npy  = 20 ;

   Double_t x = -P;
   Double_t y = -P;
   Double_t z;
   Int_t k = 0;

   Double_t dx = (2*P)/npx;
   Double_t dy = (2*P)/npy;

   TGraph2D *dt = new TGraph2D(npx*npy);

   for (Int_t i=0; i<npx; i++) {
      for (Int_t j=0; j<npy; j++) {
         z = sin(sqrt(x*x+y*y))+1;
         y = y+dx;
       x = x+dx;
       y = -P;
   dt->Draw("cont4z "); 

[quote=“couet”] dt->Draw("cont4z "); dt->GetHistogram()->SetContour(5); [/quote]

works like a charm :smiley:

Thanks a lot!