Relevant Information:
ROOT Version: 6.04.02
Platform: 3.16.0-4-amd64 GNU/Linux
Compiler: gcc version 4.9.2 (Debian 4.9.2-10+deb8u1)
I am trying to draw a square TH2 while creating room for the color bar. Here is a minimal example of my problem:
void minimal() {
auto hist = new TH2F("hist","",2,0,2,2,0,2);
hist->SetBinContent(1,1,1e3);
hist->SetBinContent(1,2,1e4);
hist->SetBinContent(2,1,1e5);
hist->SetBinContent(2,2,1e6);
auto canvas = new TCanvas("canvas","canvas",900,900);
hist->SetStats(0);
hist->Draw("colz");
}
This produces a square TH2, but the tick labels for the color bar are cut off:
So I increased the size of the right margin in order to show all the tick labels. However, now the TH2 is no longer square:
void minimal() {
auto hist = new TH2F("hist","",2,0,2,2,0,2);
hist->SetBinContent(1,1,1e3);
hist->SetBinContent(1,2,1e4);
hist->SetBinContent(2,1,1e5);
hist->SetBinContent(2,2,1e6);
auto canvas = new TCanvas("canvas","canvas",900,900);
canvas->SetRightMargin(0.2);
//canvas->SetTopMargin(0.2); // this makes the TH2F be square at the expense of a waste of empty space at the top... I do not want this
hist->SetStats(0);
hist->Draw("colz");
gPad->Update();
TPaletteAxis* palette = (TPaletteAxis*) hist->FindObject("palette");
palette->SetX1(palette->GetX1() + 0.1);
palette->SetX2(palette->GetX2() + 0.1);
gPad->Modified();
}
Which produces:
So how do I both: (1) increase the space so the tick labels of the color bar are displayed, and (2) still keep the TH2 as a square?
As you can see in the code above, I do not want to use TCanvas::SetTopMargin since this creates empty space at the top.