Logo ROOT   6.10/09
Reference Guide
annotation3d.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_graphs
3 /// \notebook
4 /// This example show how to put some annotation on a 3D plot using 3D
5 /// polylines. It also demonstrates how the axis labels can be modified.
6 /// It was created for the book:
7 /// [Statistical Methods for Data Analysis in Particle Physics](http://www.springer.com/la/book/9783319201757)
8 /// \macro_image
9 /// \macro_code
10 ///
11 /// \author Luca Lista
12 
13 void annotation3d()
14 {
15  TCanvas *c = new TCanvas("c", "c", 600, 600);
16  c->SetTheta(30);
17  c->SetPhi(50);
18  gStyle->SetOptStat(0);
21 
22  // Define and draw a surface
23  TF2 *f = new TF2("f", "[0]*cos(x)*cos(y)", -1, 1, -1, 1);
24  f->SetParameter(0, 1);
25  double s = 1./f->Integral(-1, 1, -1, 1);
26  f->SetParameter(0, s);
27  f->SetNpx(50);
28  f->SetNpy(50);
29 
30  f->GetXaxis()->SetTitle("x");
31  f->GetXaxis()->SetTitleOffset(1.4);
32  f->GetXaxis()->SetTitleSize(0.04);
33  f->GetXaxis()->CenterTitle();
34  f->GetXaxis()->SetNdivisions(505);
35  f->GetXaxis()->SetTitleOffset(1.3);
36  f->GetXaxis()->SetLabelSize(0.03);
37  f->GetXaxis()->ChangeLabel(2,-1,-1,-1,kRed,-1,"X_{0}");
38 
39  f->GetYaxis()->SetTitle("y");
40  f->GetYaxis()->CenterTitle();
41  f->GetYaxis()->SetTitleOffset(1.4);
42  f->GetYaxis()->SetTitleSize(0.04);
43  f->GetYaxis()->SetTitleOffset(1.3);
44  f->GetYaxis()->SetNdivisions(505);
45  f->GetYaxis()->SetLabelSize(0.03);
46 
47  f->GetZaxis()->SetTitle("dP/dx");
48  f->GetZaxis()->CenterTitle();
49  f->GetZaxis()->SetTitleOffset(1.3);
50  f->GetZaxis()->SetNdivisions(505);
51  f->GetZaxis()->SetTitleSize(0.04);
52  f->GetZaxis()->SetLabelSize(0.03);
53 
54  f->SetLineWidth(1);
55  f->SetLineColorAlpha(kAzure-2, 0.3);
56 
57  f->Draw("surf1 fb");
58 
59  // Lines for 3D annotation
60  double x[11] = {-0.500, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.500};
61  double y[11] = {-0.985, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 0.985};
62  double z[11];
63  for (int i = 0; i < 11; ++i) z[i] = s*cos(x[i])*cos(y[i]);
64  TPolyLine3D *g2 = new TPolyLine3D(11, x, y, z);
65 
66  double xx[2] = {-0.5, -0.5};
67  double yy[2] = {-0.985, -0.985};
68  double zz[2] = {0.11, s*cos(-0.5)*cos(-0.985)};
69  TPolyLine3D *l2 = new TPolyLine3D(2, xx, yy, zz);
70 
71  g2->SetLineColor(kRed);
72  g2->SetLineWidth(3);
73  g2->Draw();
74 
75  l2->SetLineColor(kRed);
76  l2->SetLineStyle(2);
77  l2->SetLineWidth(1);
78  l2->Draw();
79 
80  // Draw text Annotations
81  TLatex *txt = new TLatex(0.05, 0, "f(y,x_{0})");
82  txt->SetTextFont(42);
83  txt->SetTextColor(kRed);
84  txt->Draw();
85 
86  TLatex *txt1 = new TLatex(0.12, 0.52, "f(x,y)");
87  txt1->SetTextColor(kBlue);
88  txt1->SetTextFont(42);
89  txt1->Draw();
90 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:262
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF2.cxx:217
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3202
virtual void SetTheta(Double_t theta=30)
Definition: TPad.h:347
Definition: Rtypes.h:56
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
virtual void SetNdivisions(Int_t n=510, Bool_t optim=kTRUE)
Set the number of divisions for this axis.
Definition: TAttAxis.cxx:229
virtual void SetLineColorAlpha(Color_t lcolor, Float_t lalpha)
Set a transparent line color.
Definition: TAttLine.cxx:289
TAxis * GetXaxis() const
Get x axis of the function.
Definition: TF1.cxx:2131
A 3-dimensional polyline.
Definition: TPolyLine3D.h:31
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:202
void CenterTitle(Bool_t center=kTRUE)
Center axis title.
Definition: TAxis.h:184
virtual Double_t Integral(Double_t ax, Double_t bx, Double_t ay, Double_t by, Double_t epsrel=1.e-6)
Return Integral of a 2d function in range [ax,bx],[ay,by] with desired relative accuracy (default val...
Definition: TF2.cxx:620
double cos(double)
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
TAxis * GetYaxis() const
Get y axis of the function.
Definition: TF1.cxx:2142
Double_t x[n]
Definition: legend1.C:17
To draw Mathematical Formula.
Definition: TLatex.h:18
Definition: Rtypes.h:57
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
void ChangeLabel(Int_t labNum=0, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, TString labText="")
Define new text attributes for the label number "labNum".
Definition: TAxis.cxx:859
virtual void SetNpy(Int_t npy=100)
Set the number of points used to draw the function.
Definition: TF2.cxx:908
virtual void SetPhi(Double_t phi=30)
Definition: TPad.h:348
void SetHistTopMargin(Double_t hmax=0.05)
Definition: TStyle.h:359
A 2-Dim function with parameters.
Definition: TF2.h:29
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:204
virtual void SetTitleSize(Float_t size=0.04)
Set size of axis title The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:272
const Bool_t kFALSE
Definition: RtypesCore.h:92
virtual void Draw(Option_t *option="")
Draw this 3-D polyline with its current attributes.
The Canvas class.
Definition: TCanvas.h:31
double f(double x)
Double_t y[n]
Definition: legend1.C:17
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Definition: TAttLine.h:42
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1267
void SetOptTitle(Int_t tit=1)
Definition: TStyle.h:309
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition: TAttText.h:43
Definition: Rtypes.h:56
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:578
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
TAxis * GetZaxis() const
Get z axis of the function. (In case this object is a TF2 or TF3)
Definition: TF1.cxx:2153