Logo ROOT  
Reference Guide
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
5/// When an histogram is drawn with the option `COLZ`, a palette is automatically drawn
6/// vertically on the right side of the plot. It is possible to move and resize this
7/// vertical palette as shown on the left plot. The right plot demonstrates that, when the
8/// width of the palette is larger than its height, the palette is automatically drawn
9/// horizontally.
11/// \macro_image
12/// \macro_code
14/// \author Olivier Couet
16void movepalette()
18 auto c = new TCanvas("", "",0,0,1100,550);
19 c->Divide(2,1);
22 auto h1 = new TH2D("h1","h1",40,-4,4,40,-20,20);
23 auto h2 = new TH2D("h2","h2",40,-4,4,40,-20,20);
24 float px, py;
25 for (int i = 0; i < 25000; i++) {
26 gRandom->Rannor(px,py); h1->Fill(px,5*py);
27 gRandom->Rannor(px,py); h2->Fill(px,5*py);
28 }
30 TPad *p1 = (TPad *)c->cd(1);
31 TPad *p2 = (TPad *)c->cd(2);
33 p1->SetRightMargin(0.15);
34 auto palette1 = new TPaletteAxis(4.05,-15,4.5,15,h1);
35 h1->GetListOfFunctions()->Add(palette1);
37 p2->SetBottomMargin(0.2);
38 auto palette2 = new TPaletteAxis(-3.,-25,3.,-23,h2);
39 h2->GetListOfFunctions()->Add(palette2);
41 p1->cd(); h1->Draw("colz");
42 p2->cd(); h2->Draw("colz");
#define c(i)
Definition: RSha256.hxx:101
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
R__EXTERN TStyle * gStyle
Definition: TStyle.h:414
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:3348
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition: TH1.cxx:3070
TList * GetListOfFunctions() const
Definition: TH1.h:242
2-D histogram with a double per channel (see TH1 documentation)}
Definition: TH2.h:300
void Add(TObject *obj) override
Definition: TList.h:81
The most important graphics class in the ROOT system.
Definition: TPad.h:26
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition: TPad.cxx:605
The palette painting class.
Definition: TPaletteAxis.h:29
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:500
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:1590
void Draw(Option_t *option="") override=0
Default Draw method for all objects.
TH1F * h1
Definition: legend1.C:5