Logo ROOT  
Reference Guide
transpad.C File Reference

Detailed Description

View in nbviewer Open in SWAN Example of a canvas showing two histograms with different scales. The second histogram is drawn in a transparent pad

void transpad() {
TCanvas *c1 = new TCanvas("c1","transparent pad",200,10,700,500);
TPad *pad1 = new TPad("pad1","",0,0,1,1);
TPad *pad2 = new TPad("pad2","",0,0,1,1);
pad2->SetFillStyle(4000); //will be transparent
pad1->Draw();
pad1->cd();
TH1F *h1 = new TH1F("h1","h1",100,-3,3);
TH1F *h2 = new TH1F("h2","h2",100,-3,3);
for (Int_t i=0;i<100000;i++) {
Double_t x1 = r.Gaus(-1,0.5);
Double_t x2 = r.Gaus(1,1.5);
if (i <1000) h1->Fill(x1);
h2->Fill(x2);
}
h1->Draw();
pad1->Update(); //this will force the generation of the "stats" box
ps1->SetX1NDC(0.4); ps1->SetX2NDC(0.6);
pad1->Modified();
c1->cd();
//compute the pad range with suitable margins
Double_t ymax = 2000;
Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
Double_t xmin = -3;
Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
pad2->Draw();
pad2->cd();
h2->SetLineColor(kRed);
h2->Draw("][sames");
pad2->Update();
ps2->SetX1NDC(0.65); ps2->SetX2NDC(0.85);
ps2->SetTextColor(kRed);
// draw axis on the right side of the pad
TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
axis->Draw();
}
Author
Rene Brun

Definition in file transpad.C.

ymax
float ymax
Definition: THbookFile.cxx:95
TPad::Range
virtual void Range(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Set world coordinate system for the pad.
Definition: TPad.cxx:5174
TPad
Definition: TPad.h:26
TList::FindObject
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
Definition: TList.cxx:577
r
ROOT::R::TRInterface & r
Definition: Object.C:4
xmax
float xmax
Definition: THbookFile.cxx:95
Int_t
int Int_t
Definition: RtypesCore.h:45
TPave::SetX2NDC
virtual void SetX2NDC(Double_t x2)
Definition: TPave.h:85
TPad::SetFillStyle
virtual void SetFillStyle(Style_t fstyle)
Override TAttFill::FillStyle for TPad because we want to handle style=0 as style 4000.
Definition: TPad.cxx:5879
TH1::GetListOfFunctions
TList * GetListOfFunctions() const
Definition: TH1.h:240
h1
TH1F * h1
Definition: legend1.C:5
TPaveStats
Definition: TPaveStats.h:18
x1
static const double x1[5]
Definition: RooGaussKronrodIntegrator1D.cxx:346
TPad::Modified
void Modified(Bool_t flag=1)
Definition: TPad.h:414
TPave::SetX1NDC
virtual void SetX1NDC(Double_t x1)
Definition: TPave.h:84
TRandom
Definition: TRandom.h:27
xmin
float xmin
Definition: THbookFile.cxx:95
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3274
kRed
@ kRed
Definition: Rtypes.h:66
TGaxis::SetLabelColor
void SetLabelColor(Int_t labelcolor)
Definition: TGaxis.h:104
TPad::Update
virtual void Update()
Update pad.
Definition: TPad.cxx:2839
ymin
float ymin
Definition: THbookFile.cxx:95
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
Double_t
double Double_t
Definition: RtypesCore.h:59
TCanvas
Definition: TCanvas.h:23
TGaxis
Definition: TGaxis.h:23
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:572
TPad::cd
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
x2
static const double x2[5]
Definition: RooGaussKronrodIntegrator1D.cxx:364
TH1::Draw
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2997
c1
return c1
Definition: legend1.C:41
TPad::Draw
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285