Combine two canvases, move palette to middle, and SetRealAspectRatio

Dear all,

I would like to draw two canvases into a new canvas (one in the top pad and the other in the bottom), and move the palette of the bottom pad to the middle of the new canvas. By dragging the palette axis with the mouse, it can be moved only inside the bottom pad.

Besides, an error occurs when I run the macro: Error in <TCanvas::SetRealAspectRatio>: Resizing failed.

macro and root file
void Draw() {
  auto f = TFile::Open("test.root"));
  auto c0 = f->Get<TCanvas>("c0_91000");
  auto c1 = f->Get<TCanvas>("cXYPad_91000");
  //  c1->GetListOfPrimitives()->ls();

  auto c = new TCanvas("c", "", 600, 1000);
  c->Divide(1,2);
  c->cd(1);
  c0->DrawClonePad();
  c->cd(2);
  c1->SetRealAspectRatio();
  c1->DrawClonePad();
}

test.root (123.5 KB)

Thanks,
Y

The palette cannot be move outside of the pad in which the plot ti is attached too is drawn.

1 Like

Dear @couet ,
Thanks for the reply.

Another small thing is why c1->SetRealAspectRatio() fails? Because of its TH2Poly?

By construction (see the description) SetRealAspectRatio works for undivided canvases.

Probably this error is due to running the macro in batch mode.

void th2polyHoneycomb(){
   TH2Poly *hc = new TH2Poly();
   hc->SetTitle("Honeycomb example");
   hc->Honeycomb(0,0,.1,25,25);
 
   TRandom ran;
   for (int i = 0; i<3000; i++) {
      hc->Fill(ran.Gaus(2.,1), ran.Gaus(2.,1));
   }
 
   auto c = new TCanvas();
   hc->Draw("colz");
   c->SetRealAspectRatio();
}

root -b -q th2polyHoneycomb.C

Processing th2polyHoneycomb.C...
Error in <TCanvas::SetRealAspectRatio>: Resizing failed.

No, this works only when you have a single plot in the canvas.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.