Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
hist022_TH2_palette.C File Reference

Detailed Description

View in nbviewer Open in SWAN
When an histogram is drawn with the option COLZ, a palette is automatically drawn vertically on the right side of the plot.

It is possible to move and resize this vertical palette as shown on the left plot. The right plot demonstrates that, when the width of the palette is larger than its height, the palette is automatically drawn horizontally.

void hist022_TH2_palette()
{
auto c = new TCanvas("", "", 0, 0, 1100, 550);
c->Divide(2, 1);
gStyle->SetOptStat(0);
auto h1 = new TH2D("h1", "h1", 40, -4, 4, 40, -20, 20);
auto h2 = new TH2D("h2", "h2", 40, -4, 4, 40, -20, 20);
float px, py;
for (int i = 0; i < 25000; i++) {
gRandom->Rannor(px, py);
h1->Fill(px, 5 * py);
gRandom->Rannor(px, py);
h2->Fill(px, 5 * py);
}
TPad *p1 = (TPad *)c->cd(1);
TPad *p2 = (TPad *)c->cd(2);
p1->SetRightMargin(0.15);
auto palette1 = new TPaletteAxis(4.05, -15, 4.5, 15, h1);
h1->GetListOfFunctions()->Add(palette1);
p2->SetBottomMargin(0.2);
auto palette2 = new TPaletteAxis(-3., -25, 3., -23, h2);
h2->GetListOfFunctions()->Add(palette2);
p1->cd();
h1->Draw("colz");
p2->cd();
h2->Draw("colz");
}
#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
Date
October 2024
Author
Olivier Couet

Definition in file hist022_TH2_palette.C.