Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist022_TH2_palette.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/// \date October 2024
14/// \author Olivier Couet
15
17{
18 auto c = new TCanvas("", "", 0, 0, 1100, 550);
19 c->Divide(2, 1);
21
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);
27 h1->Fill(px, 5 * py);
28 gRandom->Rannor(px, py);
29 h2->Fill(px, 5 * py);
30 }
31
32 TPad *p1 = (TPad *)c->cd(1);
33 TPad *p2 = (TPad *)c->cd(2);
34
35 p1->SetRightMargin(0.15);
36 auto palette1 = new TPaletteAxis(4.05, -15, 4.5, 15, h1);
38
39 p2->SetBottomMargin(0.2);
40 auto palette2 = new TPaletteAxis(-3., -25, 3., -23, h2);
41 h2->GetListOfFunctions()->Add(palette2);
42
43 p1->cd();
44 h1->Draw("colz");
45 p2->cd();
46 h2->Draw("colz");
47}
#define c(i)
Definition RSha256.hxx:101
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
The Canvas class.
Definition TCanvas.h:23
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3315
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3037
TList * GetListOfFunctions() const
Definition TH1.h:260
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:356
void Add(TObject *obj) override
Definition TList.h:81
The most important graphics class in the ROOT system.
Definition TPad.h:28
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:1642
TH1F * h1
Definition legend1.C:5