Multiple TGraph2D in a single plot

Hi everybody,
I would like to draw 2 TGraph2D objects together, for example create 6 red points (markers) plus another set of n blue points. I tried using the draw option “same” or “P” but it didn’t work, can you help me.
Thank you very much.

[code]TGraph2D *g1 = new TGraph2D(3);
TGraph2D *g2 = new TGraph2D(3);

 g1->SetPoint(0,1,0,0);
 g1->SetPoint(1,0,1,0);
 g1->SetPoint(2,0,0,1);
 g2->SetPoint(3,-1,0,0);
 g2->SetPoint(4,0,-1,0);
 g2->SetPoint(5,0,0,-1);
  
 g1->SetMarkerStyle(20);
 g1->SetMarkerColor(kBlue);
 g1->SetMarkerSize(1.5);
 g2->SetMarkerStyle(20);
 g2->SetMarkerColor(kRed);
 g2->SetMarkerSize(1.5);

 g1->Draw("P");
 g2->Draw("same");[/code]
g2->Draw("P same");

Hi couet,
I tried but it didn’t work. You can see it in my macro at http://root.cern.ch/phpBB2/viewtopic.php?t=7576.
Thank very much for all your help.

It works for me. The macro is:

{
   TGraph2D *g1 = new TGraph2D(3);
   TGraph2D *g2 = new TGraph2D(3);

   g1->SetPoint(0,1,0,0);
   g1->SetPoint(1,0,1,0);
   g1->SetPoint(2,0,0,1);
   g2->SetPoint(3,-1,0,0);
   g2->SetPoint(4,0,-1,0);
   g2->SetPoint(5,0,0,-1);
                                           
   g1->SetMarkerStyle(20);
   g1->SetMarkerColor(kBlue);
   g1->SetMarkerSize(1.5);
   g2->SetMarkerStyle(20);
   g2->SetMarkerColor(kRed);
   g2->SetMarkerSize(1.5);

   g1->Draw("P");
   g2->Draw("P same");
}

It gives the image:


It’s strange, but for me the same code gives me that:
How is your Root version, my is 5.21/05 trunk@25949

Le me try on windows.

Your and my points in the graphic are not correct. The red points have coordenates (-1,0,0),(0,-1,0),(0,0,-1) [defined in the code] and not as is showed (0.5,0.5,0.5),(0,1,1),(1,1,1).
It is strange.

On windows I see the same picture as you do. Strange. I have no answer yet.

The red point are not correct because the two data set do not have the same axis ranges this is a limitation. in fact the same option does not really work unless they have the same range. Sometimes ago I did the following macro to illustrate it:

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

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

   TH2F *h1 = new TH2F("h1","h1",10,0,10,10,0,10);
   h1->SetDirectory(0);
   h1->SetMinimum(0);
   h1->SetMaximum(10);

   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->SetHistogram(h1);
   g2d1->Draw("P0 TRI1");

   TH2F *h2 = new TH2F("h2","h2",10,0,10,10,0,10);
   h2->SetDirectory(0);
   h2->SetMinimum(0);
   h2->SetMaximum(10);

   Double_t x2[4] = {5,5,6,6};
   Double_t y2[4] = {5,6,5,6};
   Double_t z2[4] = {5,6,7,8};

   TGraph2D *g2d2 = new TGraph2D(4,x2,y2,z2);
   g2d2->SetHistogram(h2);
   g2d2->Draw("P0 TRI1 SAME");
}

Would be better to have only one TGraph2D.

Note that the macro I sent you does not work very well either on window. Same problem as the previous one. Seems to me it appears you use TGraph2D only to draw markers ? right ? why not using a TPolyMarker3D in that case ?

Hi couet,
Thanks for your help. I tried with TPolyMarker3D, and probably it’s the best solution, but I would like to know 2 things: how I draw the axis (option “”); and how I set the title (if it’s possible with this class). I look at the root class but there isn’t theses informations.
Thank you another time.

[code]TPolyMarker3D *g1 = new TPolyMarker3D(nb);

 for(int i=0;i<nb;i++){
	 g1->SetPoint(i,x[i],y[i],z[i]);
 }
// TGraph2D *g2 = new TGraph2D(7);

 TPolyMarker3D *g2 = new TPolyMarker3D(7);
 g2->SetPoint(0,1,0,0);
 g2->SetPoint(1,0,1,0);
 g2->SetPoint(2,0,0,1);
 g2->SetPoint(3,0,0,0);
 g2->SetPoint(4,-1,0,0);
 g2->SetPoint(5,0,-1,0);
 g2->SetPoint(6,0,0,-1);


 char PosVect[100]= " Vectors Position, nb = ";
 char T15[100]="";

 sprintf(T15,"%d",nb);
 strcat(PosVect,T15);
 //g1->SetTitle(PosVect);


 g1->SetMarkerStyle(20);
 g1->SetMarkerColor(kBlue);
 g1->SetMarkerSize(1.5);
 g2->SetMarkerStyle(20);
 g2->SetMarkerColor(kRed);
 g2->SetMarkerSize(1.5);

 g1->Draw("A");
 g2->Draw("A"); [/code]


{
   gStyle->SetOptStat(0);

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

   TPolyMarker3D *pm3d1 = new TPolyMarker3D(3);
   pm3d1->SetPoint(0,1,0,0);
   pm3d1->SetPoint(1,0,1,0);
   pm3d1->SetPoint(2,0,0,1);

   pm3d1->SetMarkerSize(2);
   pm3d1->SetMarkerColor(kBlue);
   pm3d1->SetMarkerStyle(20);   

   pm3d1->Draw();

   TPolyMarker3D *pm3d2 = new TPolyMarker3D(3);
   pm3d2->SetPoint(0,-1,0,0);
   pm3d2->SetPoint(1,0,-1,0);
   pm3d2->SetPoint(2,0,0,-1);

   pm3d2->SetMarkerSize(2);
   pm3d2->SetMarkerColor(kRed);
   pm3d2->SetMarkerStyle(20);

   pm3d2->Draw();
}

Perfect, thank you very much!!!
It’s great.