Bjorn1
October 31, 2013, 6:46pm
1
Hi,
I’m confused about the right way of using TCanvas::SetTheta() and TCanvas::SetPhi(). E.g. I would like to draw a TGraph2D with PCOLZ option and view it
a) in the x-y plane
b) in the y-z plane
c)- in the x-z plane.
What values for theta and phi do I have to use you achieve that?
E.g. for c) I tried the following but the result doesn’t look right at all, I assume because I used the wrong values for theta and phi.
TGraph2D *gr = new TGraph2D(3);
gr->SetPoint( 0, -10e-5, 30e-5, 9.);
gr->SetPoint( 1, -9e-5, -30e-5, 7.);
gr->SetPoint( 2, -10e-5, -90e-5, 8.);
gr->SetMarkerStyle(21);
TCanvas* canvas = new TCanvas();
double theta = 0;
double phi = 0;
canvas->SetTheta( theta. );
canvas->SetPhi( phi );
gr->Draw("pcolz");
Cheers,
Bjorn
couet
November 1, 2013, 8:48am
2
The simplest is that you position your plot interactively with the mouse and then save the result in a .C file.
Then look in that file what the the values of theta and phi.
Bjorn1
November 6, 2013, 4:54pm
3
Hi,
thanks for hint, but now I’m even more confused. It llooks like theta=0, phi=0 gives indeed the x-z-plane but the plot looks only reasonable when I set the range of the hidden y-axis by hand (see UserYRange.png produced by code below). Without doing that the plot looks totally different ( see DefaultYRange.png).
{
TGraph2D *gr = new TGraph2D(3);
gr->SetPoint( 0, -10e-5, 30e-5, 9.);
gr->SetPoint( 1, -9e-5, -30e-5, 7.);
gr->SetPoint( 2, -10e-5, -90e-5, 8.);
gr->SetMarkerStyle(21);
gr->GetXaxis()->SetTitle("x axis");
gr->GetYaxis()->SetTitle("y axis");
gr->GetZaxis()->SetTitle("z axis");
TCanvas* canvas = new TCanvas();
canvas->SetTheta(0);
canvas->SetPhi(0);
gr->Draw("pcolz");
canvas->SaveAs("DefaultYRange.png");
gr->GetYaxis()->SetRangeUser(-100e-5,50e-5);
gr->Draw("pcolz");
canvas->SaveAs("UserYRange.png");
}
Why is the call of SetRangeUser on the hidden axis necessary?
Cheers,
Bjorn
couet
November 6, 2013, 5:26pm
4
Ok lets simplify the issue. When I run:
{
TGraph2D *gr = new TGraph2D(3);
gr->SetPoint( 0, -10e-5, 30e-5, 9.);
gr->SetPoint( 1, -9e-5, -30e-5, 7.);
gr->SetPoint( 2, -10e-5, -90e-5, 8.);
gr->SetMarkerStyle(21);
gr->GetXaxis()->SetTitle("x axis");
gr->GetYaxis()->SetTitle("y axis");
gr->GetZaxis()->SetTitle("z axis");
TCanvas* canvas = new TCanvas();
gr->Draw("pcol");
}
I do not see any point at z=9 … which is weird.
I will investigate that.
couet
November 6, 2013, 5:29pm
5
but :
gr->SetPoint( 0, 1, 2, 9.);
gr->SetPoint( 1, 2, 3, 7.);
gr->SetPoint( 2, 4, 5, 8.);
is ok
couet
November 7, 2013, 2:17pm
6
There is a precision issue I am trying to work around.
Not real solution yet.
couet
November 7, 2013, 3:26pm
7
I found a solution:
{
Double_t x[3], y[3], z[3];
x[0] = -0.01000; y[0] = 1.00000; z[0] = 9.;
x[1] = -0.00005; y[1] = -0.00002; z[1] = 7.;
x[2] = -0.00009; y[2] = -0.00003; z[2] = 8.;
Double_t xmin = x[0], xmax = x[0];
Double_t ymin = y[0], ymax = y[0];
Double_t zmin = z[0], zmax = z[0];
for (int i=1; i<3; i++) {
if (x[i]<xmin) xmin = x[i];
if (x[i]>xmax) xmax = x[i];
if (y[i]<ymin) ymin = y[i];
if (y[i]>ymax) ymax = y[i];
if (z[i]<zmin) zmin = z[i];
if (z[i]>zmax) zmax = z[i];
}
Double_t eps = 0.005;
TH2F *h = new TH2F("h","h",10,xmin-eps,xmax+eps,
10,ymin-eps,ymax+eps);
h->SetMinimum(zmin-eps);
h->SetMaximum(zmax+eps);
TGraph2D *gr = new TGraph2D(3,x,y,z);
gr->SetMarkerStyle(21);
h->Draw("Lego");
gr->Draw(" PCOL SAME");
h->GetXaxis()->SetTitle("x axis");
h->GetYaxis()->SetTitle("y axis");
h->GetZaxis()->SetTitle("z axis");
}
Bjorn1
November 7, 2013, 7:37pm
8
Thanks a lot for this workaround!
For reference: Values for theta and phi seem to be:
[code] // xz
canvas->SetTheta(0);
canvas->SetPhi(0);
// yz
canvas->SetTheta(0);
canvas->SetPhi(-90);
// xy
canvas->SetTheta(90);
canvas->SetPhi(0);
[/code]
Cheers,
Bjorn
couet
November 8, 2013, 9:44am
9
an other possible way:
{
Double_t x[3], y[3], z[3];
x[0] = -0.01000; y[0] = 1.00000; z[0] = 9.;
x[1] = -0.00005; y[1] = -0.00002; z[1] = 7.;
x[2] = -0.00009; y[2] = -0.00003; z[2] = 8.;
TGraph2D *gr = new TGraph2D(3,x,y,z);
gr->SetMarkerStyle(21);
gr->SetMargin(0.2);
gr->Draw(" PCOL ");
}