Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
transpad.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// Example of a canvas showing two histograms with different scales.
5/// The second histogram is drawn in a transparent pad
6///
7/// \macro_image
8/// \macro_code
9///
10/// \author Rene Brun
11
12void transpad()
13{
14 TCanvas *c1 = new TCanvas("c1","transparent pad",200,10,700,500);
15 TPad *pad1 = new TPad("pad1","",0,0,1,1);
16 TPad *pad2 = new TPad("pad2","",0,0,1,1);
17 pad2->SetFillStyle(4000); //will be transparent
18 pad1->Draw();
19 pad1->cd();
20
21 TH1F *h1 = new TH1F("h1","h1",100,-3,3);
22 TH1F *h2 = new TH1F("h2","h2",100,-3,3);
23 TRandom r;
24 for (Int_t i=0;i<100000;i++) {
25 Double_t x1 = r.Gaus(-1,0.5);
26 Double_t x2 = r.Gaus(1,1.5);
27 if (i <1000) h1->Fill(x1);
28 h2->Fill(x2);
29 }
30 h1->Draw();
31 pad1->Update(); //this will force the generation of the "stats" box
33 ps1->SetX1NDC(0.4); ps1->SetX2NDC(0.6);
34 pad1->Modified();
35 c1->cd();
36
37 //compute the pad range with suitable margins
38 Double_t ymin = 0;
39 Double_t ymax = 2000;
40 Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
41 Double_t xmin = -3;
42 Double_t xmax = 3;
43 Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
44 pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
45 pad2->Draw();
46 pad2->cd();
47 h2->SetLineColor(kRed);
48 h2->Draw("][sames");
49 pad2->Update();
50 TPaveStats *ps2 = (TPaveStats*)h2->GetListOfFunctions()->FindObject("stats");
51 ps2->SetX1NDC(0.65); ps2->SetX2NDC(0.85);
52 ps2->SetTextColor(kRed);
53
54 // draw axis on the right side of the pad
55 TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
56 axis->SetLabelColor(kRed);
57 axis->Draw();
58}
59
60
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
@ kRed
Definition Rtypes.h:66
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char x2
Option_t Option_t TPoint TPoint const char x1
float xmin
float ymin
float xmax
float ymax
virtual void SetTextColor(Color_t tcolor=1)
Set the text color.
Definition TAttText.h:44
The Canvas class.
Definition TCanvas.h:23
The axis painter class.
Definition TGaxis.h:24
void SetLabelColor(Int_t labelcolor)
Definition TGaxis.h:104
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:621
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3340
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3062
TList * GetListOfFunctions() const
Definition TH1.h:244
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:274
The most important graphics class in the ROOT system.
Definition TPad.h:28
void SetFillStyle(Style_t fstyle) override
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition TPad.cxx:5961
void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2) override
Set world coordinate system for the pad.
Definition TPad.cxx:5233
void Update() override
Update pad.
Definition TPad.cxx:2839
void Modified(Bool_t flag=true) override
Mark pad modified Will be repainted when TCanvas::Update() will be called next time.
Definition TPad.cxx:7255
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:597
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1268
The histogram statistics painter class.
Definition TPaveStats.h:18
virtual void SetX1NDC(Double_t x1)
Definition TPave.h:82
virtual void SetX2NDC(Double_t x2)
Definition TPave.h:83
This is the base class for the ROOT Random number generators.
Definition TRandom.h:27
return c1
Definition legend1.C:41
TH1F * h1
Definition legend1.C:5