Skip to content

Improper behavior of TCanvas::Divide #20138

@rlalik

Description

@rlalik

Check duplicate issues.

  • Checked for duplicates

Description

Documentation for TCanvas::Divide says:

Automatic pad generation by division.

  • The current canvas is divided in nx by ny equal divisions (pads).
  • xmargin is the space along x between pads in percent of canvas.
  • ymargin is the space along y between pads in percent of canvas.
  • color is the color of the new pads. If 0, color is the canvas color.

But setting margins to 0 results in:

  1. Not setting up colors of subpards
  2. Adding top-right padding to the main canvas.

The documentation also says that:

Note3: in case xmargin <=0 and ymargin <= 0, there is no space between pads. The current pad margins are recomputed to optimize the layout.

Not sure what the second sentence means, what pad margins are recomputed?

Reproducer

Here a couple of examples of proper and improper behaviors:

  1. This works as expected - OK
{
    TCanvas * can = new TCanvas("can", "can", 800, 800);
    can->Divide(2, 2, 0.01, 0.01, 2);
}
Image
  1. This gives white pads whereas they should be red - NOT OK
{
    TCanvas * can = new TCanvas("can", "can", 800, 800);
    can->Divide(2, 2, 0.0, 0.0, 2);
}
Image
  1. After putting colours manually, we see odd top-right margin - NOT OK
{
    TCanvas * can = new TCanvas("can", "can", 800, 800);
    
    can->Divide(2, 2, 0.0, 0.0, 2);
    
    can->cd(1);
    gPad->SetFillColor(30);
    gPad->Modified();
    gPad->Update();
    
    can->cd(2);
    gPad->SetFillColor(38);
    gPad->Modified();
    gPad->Update();
    
    can->cd(3);
    gPad->SetFillColor(41);
    gPad->Modified();
    gPad->Update();
    
    can->cd(4);
    gPad->SetFillColor(42);
    gPad->Modified();
    gPad->Update();
    
    can->cd(0);
    gPad->SetFillColor(2);
    gPad->Modified();
    gPad->Update();
}
Image

ROOT version

ROOT v6.36.04
Built for linuxx8664gcc on Sep 05 2025, 08:28:36
From tags/6-36-04@6-36-04
With 
Binary directory: /usr/bin

Installation method

Gentoo, build from sources

Operating system

Gentoo

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions