technical/procedural

Written by

in

Understanding Subpads: How to Divide and Customize ROOT Pads

In data analysis frameworks like CERN’s ROOT Framework, a TCanvas represents the primary graphic window. By default, a canvas behaves as a single drawing area, but it can be subdivided into smaller, independent graphic zones known as subpads using the TPad class. Mastering subpad division and styling allows you to display complex, multi-panel data plots—such as data-to-simulation comparisons or multi-variable distributions—within a single window. Methods for Dividing a Pad

You can partition your drawing area into subpads using two distinct workflows depending on whether your layout is uniform or asymmetric. 1. Automatic Grid Division using Divide()

For uniform grids (such as a 2×2 or 3×2 matrix of equal plots), use the TPad::Divide() method. This automatically splits the target pad into a specified number of columns and rows.

// Create a canvas and divide it into a 2x2 grid TCanvasc1 = new TCanvas(“c1”, “Grid Example”, 800, 600); c1->Divide(2, 2); Use code with caution.

To draw within a specific subpad generated by Divide(), use the .cd(index) method. Note that subpad indexing starts at 1 and increments from left-to-right, top-to-bottom: c1->cd(1); opens the top-left subpad. c1->cd(4); opens the bottom-right subpad. 2. Manual Coordinate Specification for Custom Layouts

When creating asymmetric layouts—such as a large main plot on top with a narrow ratio panel at the bottom—the automatic grid spacing from Divide() will distort your axes. Instead, manually declare individual TPad objects by defining their exact coordinates using Normalized Device Coordinates (NDC), which span from 0.0 to 1.0.

TCanvas *c2 = new TCanvas(“c2”, “Ratio Layout”, 800, 800); // Main upper pad (occupies 70% of height, from y=0.3 to y=1.0) TPad *padTop = new TPad(“padTop”, “Main Plot”, 0.0, 0.3, 1.0, 1.0); padTop->Draw(); // Bottom ratio pad (occupies 30% of height, from y=0.0 to y=0.3) TPad *padBottom = new TPad(“padBottom”, “Ratio Plot”, 0.0, 0.0, 1.0, 0.3); padBottom->Draw(); Use code with caution. Customizing Subpad Margins and Spacing

When subpads sit tightly against one another, their bounding boxes can clip or overlap axis labels and titles. You can resolve this behavior by modifying the pad margins. Removing the Gap Between Adjacent Subpads

If you want plots to touch seamlessly (sharing an axis), you can pass explicit padding parameters to the Divide() method:

// Syntax: Divide(columns, rows, xmargin, ymargin) c1->Divide(1, 2, 0.0, 0.0); Use code with caution.

Divide canvas: merge subpads into one single … – ROOT Forum