A plane in a 2D graph at a fixed Z

Hi,

I have a 2D graph and I am trying to draw a transparent plane at z = 9.2.
I defined the plane as a TF2 object with the equation (0x + 0y + 9.2). The problem is, the plane is always drawn at z = 8.85, no matter what I set instead of “9.2”.
And also I don’t know how to make the plane transparent.

Thanks,

Here is my code:

{
TCanvas c1(“c1”, “Number of Events”, 1400, 1000); c1.SetTickx(1); c1.SetTicky(1); //c1.SetLogy();

Double_t xxx[9] = {8.375, 8.5, 8.625, 8.750, 8.875, 9, 9.125, 9.250, 9.375};
Double_t yyx[9] = {12, 10, 8, 7, 6, 5, 4, 2, 1};
Double_t Sig[9] = {42, 40, 38, 37, 36, 35, 34, 32, 31};

TGraph2D *g = new TGraph2D(9,Sig, yyx, xxx);

//g->SetTitle(“L=3000/fb”);
g->GetZaxis()->SetTitle(“M (TeV)”);
g->GetXaxis()->SetTitle(“Significance”);
g->GetYaxis()->SetTitle(“Number of Events”);
g->GetYaxis()->SetTitleOffset(2);
g->GetXaxis()->SetTitleOffset(2);
g->GetZaxis()->SetTitleOffset(1.4);
g->GetYaxis()->CenterTitle(kTRUE);
g->GetXaxis()->CenterTitle(kTRUE);
g->SetMarkerStyle(21);
g->SetMarkerSize(1.5);
g->SetMarkerColor(kBlue);
g->SetLineWidth(2);

TF2 myPlane = new TF2(“myPlane”,"0x + 0*y + 9.2");

myPlane->SetNpy(200);
myPlane->SetNpx(200);

myPlane->SetLineColorAlpha(kBlack, 0.0001);

g->Draw(“P”);

c1.Update();

myPlane->Draw(“surf1 same”);

c1.SaveAs(“ques.png”);
}

Hi,
for what concern the alpha color, you should use SetFillColorAlpha instead
of SetLineColorAlpha.
I don’t know how to solve the problem with the z of the plane, I don’t have this issue.

Cheers
S

Thanks to your comment, I could fix the color problem.

I changed the order of drawing the plane and the graph, first the plane is drawn and then the graph, and the problem is solved.

The problem that I am struggling with is to limit the Z axis to the [8, 10] region. “SetRange” and “SetRangeUser” do not work.

Here is the corrected code:

{
  TCanvas c1("c1", "Number of Events", 1400, 1000); c1.SetTickx(1); c1.SetTicky(1); //c1.SetLogy(); 
  
  Double_t xxx[9] = {8.375,  8.5, 8.625, 8.750, 8.875, 9, 9.125, 9.250, 9.375};
  Double_t yyx[9] = {12, 10, 8, 7, 6, 5, 4, 2, 1};
  Double_t Sig[9] = {42, 40, 38, 37, 36, 35, 34, 32, 31};

 
  TGraph2D *g = new TGraph2D(9,Sig, yyx, xxx);

  
  g->SetMarkerStyle(21);
  g->SetMarkerSize(1.5);
  g->SetMarkerColor(kBlack);
  g->SetLineWidth(2);

  TF2 *myPlane = new TF2("myPlane","0*x + 0*y + 9.2", 30, 43, 0, 13);
  
  myPlane->SetNpy(200);
  myPlane->SetNpx(200);

  myPlane->SetFillColorAlpha(kRed, 0.9);
  myPlane->SetLineColorAlpha(kRed, 0.9);

  myPlane->GetZaxis()->SetTitle("M (TeV)");
  myPlane->GetXaxis()->SetTitle("Significance");
  myPlane->GetYaxis()->SetTitle("Number of Events");
  myPlane->GetYaxis()->SetTitleOffset(2);
  myPlane->GetXaxis()->SetTitleOffset(2);
  myPlane->GetZaxis()->SetTitleOffset(1.4);
  myPlane->GetYaxis()->CenterTitle(kTRUE);
  myPlane->GetXaxis()->CenterTitle(kTRUE);

  c1.Update();

  


  
  myPlane->Draw("surf1");

  c1.Update();

  g->Draw("P same");

  
  
  c1.SaveAs("ques.png");
}

Hi,
Try to use myPlane->SetMinimum(8) and myPlane->SetMaximum(10), I think this should work

S

It worked. Thanks a lot.

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