How to plot 2D filled contours?

Hi,

I would like to plot 2D uniformally filled contours (for excluded regions of parameter spaces) with a unique specified color. However, I do not find which function to use: TH2D, TGraph2D, … I was able to generate contours with TGraph2D, but I need to fill them…

Could someone please tell me how to do so?

Thanks,
Alexandre

1 Like

The contour options are CONT0, etc… are described here:
root.cern.ch/root/html/THistPain … nter:Paint

Hi,

Thank you for your answer. However, I tested all the CONT option with the TH2D function, but I never got what I would like. Either I get only contour lines, or contours filled with several colors, instead of a contour filled with a unique color.

Thank you anyway,
Alexandre

I think you should try to change the number of contours like in the following example:

{

   TCanvas *c  = new TCanvas("c","Contours",0,0,800,700);
   c->Divide(2,3,0,0);

   TF2 *f2 = new TF2("f2","0.1+1000*((1-(x-2)*(x-2))*(1-(y-2)*(y-2)))",1,3,1,3);  
   f2->SetFillStyle(1000);
   f2->SetLineWidth(1);

   double contours[3];
   contours[0] = 500;
   contours[1] = 700;
   contours[2] = 900;
   f2->SetContour(3,contours);

   Int_t colors[3] = {kRed, kYellow, kGreen};
   gStyle->SetPalette(3,colors);

   c->cd(1);  
   f2->Draw("cont0 z");
   f2->Draw("cont3 same");

   c->cd(2);  
   c_2->SetLogx();
   c_2->SetLogy();
   c_2->SetLogz();
   f2->Draw("cont0 z");
   f2->Draw("cont3 same");

   c->cd(3);  
   f2->Draw("cont4 z");
   f2->Draw("cont3 same");

   c->cd(4);  
   c_4->SetLogx();
   c_4->SetLogy();
   c_4->SetLogz();
   f2->Draw("cont4 z");

   c->cd(5);  
   f2->Draw("colz");
   f2->Draw("cont3 same");

   c->cd(6);  
   c_6->SetLogx();
   c_6->SetLogy();
   c_6->SetLogz();
   f2->Draw("colz");
   f2->Draw("cont3 same");
}
1 Like

Thank you, that was exactly what I was looking for!

Best,
Alexandre