TGraph2D and marker color % z value

Hello,

similarly to option colz with TH2 bins (or TGraph2D), I would like to draw a TGraph2D on a 2D plane with a different marker color proportionnal to z value for every point. Is it now feasible ?

Thanks,
Renaud.

This is the option PCOL
See:
root.cern.ch/root/html/TGraph2D. … aph2D:Draw

[quote=“couet”]This is the option PCOL
See:
root.cern.ch/root/html/TGraph2D. … aph2D:Draw[/quote]

I am looking for the same function. As far as I know, the PCOL option draws a graph in a 3D space, but I would like to draw it on a 2D plane. I can manually do it putting number of TMarker and choosing colors from TPaletteAxis. But I would like to do the same thing in an easier way.

This option draws a graph in 3D. The z-value is mapped on both the Z position and the color map. Simply change the angles to the appropriate way (to see the graph from top) and you will get what you are looking for.

Thank you, Olivier. Yes. SetPhi and SetTheta work fine. But it seems that it doesn’t work when I Draw(“pcol same”) on other pre-drawn 2D histograms.

void graph2dsame4()
{
   gStyle->SetOptStat(0);
   gStyle->SetOptFit(1111);

   TCanvas *c = new TCanvas("c","Graph2D example",0,0,800,800);

   TH3F *frame3d = new TH3F("frame3d","frame3d",10,0,10,10,1,10,10,0,10);
   frame3d->Draw();

   Double_t x1[4] = {1,1,2,2};
   Double_t y1[4] = {1,2,1,2};
   Double_t z1[4] = {1,2,3,4};
   TGraph2D *g2d1 = new TGraph2D(4,x1,y1,z1);
   g2d1->SetMarkerStyle(20);   
   g2d1->Draw("PCOL SAME");  

   Double_t x2[4] = {5,5,7,7};
   Double_t y2[4] = {5,7,5,7};
   Double_t z2[4] = {5,7,3,8};
   TGraph2D *g2d2 = new TGraph2D(4,x2,y2,z2);
   g2d2->SetMarkerStyle(20);

   g2d2->Draw("PCOL SAME");
}