Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
movepalette.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// When an histogram is drawn with the option `COLZ`, a palette is automatically drawn
5/// vertically on the right side of the plot. It is possible to move and resize this
6/// vertical palette as shown on the left plot. The right plot demonstrates that, when the
7/// width of the palette is larger than its height, the palette is automatically drawn
8/// horizontally.
9///
10/// \macro_image
11/// \macro_code
12///
13/// \author Olivier Couet
14
15void movepalette()
16{
17 auto c = new TCanvas("", "",0,0,1100,550);
18 c->Divide(2,1);
20
21 auto h1 = new TH2D("h1","h1",40,-4,4,40,-20,20);
22 auto h2 = new TH2D("h2","h2",40,-4,4,40,-20,20);
23 float px, py;
24 for (int i = 0; i < 25000; i++) {
25 gRandom->Rannor(px,py); h1->Fill(px,5*py);
26 gRandom->Rannor(px,py); h2->Fill(px,5*py);
27 }
28
29 TPad *p1 = (TPad *)c->cd(1);
30 TPad *p2 = (TPad *)c->cd(2);
31
32 p1->SetRightMargin(0.15);
33 auto palette1 = new TPaletteAxis(4.05,-15,4.5,15,h1);
34 h1->GetListOfFunctions()->Add(palette1);
35
36 p2->SetBottomMargin(0.2);
37 auto palette2 = new TPaletteAxis(-3.,-25,3.,-23,h2);
38 h2->GetListOfFunctions()->Add(palette2);
39
40 p1->cd(); h1->Draw("colz");
41 p2->cd(); h2->Draw("colz");
42}
#define c(i)
Definition RSha256.hxx:101
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
R__EXTERN TStyle * gStyle
Definition TStyle.h:436
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition TAttPad.cxx:99
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition TAttPad.cxx:119
The Canvas class.
Definition TCanvas.h:23
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3346
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3068
TList * GetListOfFunctions() const
Definition TH1.h:245
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:358
void Add(TObject *obj) override
Definition TList.h:81
The most important graphics class in the ROOT system.
Definition TPad.h:28
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:693
The palette painting class.
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition TRandom.cxx:507
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:1640
TH1F * h1
Definition legend1.C:5