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/// \preview 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
16void hist022_TH2_palette()
17{
18 auto c = new TCanvas("", "", 0, 0, 1100, 550);
19 c->Divide(2, 1);
20 gStyle->SetOptStat(0);
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);
37 h1->GetListOfFunctions()->Add(palette1);
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
externTRandom * gRandom
Definition TRandom.h:62
externTStyle * gStyle
Definition TStyle.h:442
virtual void SetBottomMargin(Float_t bottommargin)
Set Pad bottom margin in fraction of the pad height.
Definition TAttPad.cxx:98
virtual void SetRightMargin(Float_t rightmargin)
Set Pad right margin in fraction of the pad width.
Definition TAttPad.cxx:118
The Canvas class.
Definition TCanvas.h:23
2-D histogram with a double per channel (see TH1 documentation)
Definition TH2.h:400
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:694
void Draw(Option_t *option="") override=0
Default Draw method for all objects.
TH1F * h1
Definition legend1.C:5