KAHIBARO
Discord Login Register

25.5. E. Common Drawing Options

Overview

This appendix collects the most commonly used ROOT drawing options for histograms, graphs, and 2D plots. It is meant as a quick reference while you work through the other chapters.

Whenever you pass a string to Draw(), for example

cpp
h1->Draw("E1");
g->Draw("ALP");

you are selecting one or more of these options, often combined in the same string.

Important rule: Drawing options are case sensitive. "colz" is not the same as "COLZ", and "hist" is not the same as "HIST".

1D Histogram Drawing Options

ROOT histograms, such as TH1F and TH1D, have a rich set of options. Some of the most used are listed here.

OptionEffect
(empty string)Default 1D histogram draw. Bars with error bars if errors are set.
"HIST"Draws histogram as a continuous line connecting bin contents, without error bars and without markers. Efficient for many bins.
"HIST SAME"Draws a histogram line on top of an existing plot without clearing the canvas.
"E"Draws error bars only, with no connecting line and no markers.
"E1"Error bars with small horizontal lines (caps) at the end of each bar.
"E2"Error bands, draws filled areas representing errors.
"E3"Error bands with a different style; often used similar to E2.
"P"Draws markers at bin centers, no line. Useful if you want histogram as points.
"L"Draws a line through bin centers, no markers.
"LP"Line plus markers at bin centers.
"B"Draws histogram with bar chart style bars.
"BAR"Alternative bar style, vertical bars.
"C"Draws a smooth curve (spline) through the histogram.
"TEXT"Draws the bin contents as text inside or above the bins.
"AXIS"Draws only the axes of the histogram, no content.
"SAME"Do not erase the pad, draw on top of existing content. Usually combined with other options.

Typical combinations for 1D histograms:

ExampleDescription
"HIST"Line-style histogram, quick for large statistics.
"E1"Points with error bars and small caps, common for data.
"HIST SAME"Overlay another histogram as a line on existing axes.
"E1 SAME"Overlay data points with error bars on an existing histogram (often Monte Carlo).
"P E1"Markers with error bars.
"TEXT"Show numbers in bins, useful for low statistics or debugging.

Common pitfall: If you forget "SAME" when drawing a second histogram, ROOT clears the pad and erases the first plot.

2D Histogram and Image Options

For TH2F, TH2D, and similar 2D histograms, ROOT offers several visual styles.

OptionEffect
"SCAT"Draws a scatter plot using the bin centers of non zero bins.
"COL"Draws a color map, each bin is a colored box proportional to content, no color scale bar.
"COLZ"Same as COL but adds a vertical color palette (Z axis) on the right. Very common.
"BOX"Draws filled boxes with size proportional to bin size and color to content.
"BOX1"Similar to BOX with an improved visual appearance.
"TEXT"Draws numerical bin contents as text in each cell. Often used together with COLZ.
"CONT"Draws contour lines only.
"CONTZ"Contour lines with Z scale bar on the right.
"CONT1"Single contour style, often smoother lines.
"SURF"3D surface plot, default style.
"SURF1"3D surface with colored top and hidden line removal.
"SURF2"Surface with a different shading algorithm.
"SURF3"Surface as a mesh grid.
"SURF4"Another surface style, often useful for wireframe like view.
"LEGO"3D blocks (lego style) for each bin.
"LEGO1"Lego with surface optimization and hidden line removal.
"LEGO2"Lego + color shading from Z values.
"Z"Requests that the Z axis (color scale) be drawn if relevant. Often implied by COLZ.
"SAME"Overlay on existing content.

Examples of common 2D drawing patterns:

cpp
h2->Draw("COLZ");      // Color map with palette
h2->Draw("CONT4Z");    // Several contour lines + palette
h2->Draw("LEGO2");     // 3D lego plot
h2->Draw("TEXT COLZ"); // Numbers on top of color cells

Important rule: For 2D histograms, ROOT uses X and Y for position and Z for content. Options like COL, SURF, and LEGO all represent the Z content in different visual forms.

TGraph and TGraphErrors Options

Graphs (TGraph, TGraphErrors, TGraphAsymmErrors) use a slightly different set of options, but many are parallel to histogram options.

OptionEffect
"P"Draws markers only (points). Default for TGraph.
"L"Draws lines connecting the points.
"LP"Line plus markers, very common.
"C"Smooth curve (spline) through the points.
"A"Forces drawing of axes, does not reuse existing axes. Needed the first time in a pad.
"AP"Axes plus markers. Frequently used for the first drawn graph.
"AL"Axes plus connected line.
"ALP"Axes plus line plus markers, a standard choice.
"*", "."Special marker styles (important for dense scatter plots).
"B"Draws lines as boxes connecting points, less common.

For graphs with errors:

OptionEffect
"E"Error bars only.
"P"Markers only.
"PE"Markers with error bars, common for TGraphErrors.
"APL"Axes plus line plus markers (no error bars).
"APLE"Axes, line, markers, and error bars all together.

Typical usage:

cpp
g->Draw("AP");            // First graph: axes + points
g_err->Draw("P SAME");    // Overlay another graph (no new axes)
g_err->Draw("PE SAME");   // Overlay points with error bars

Important rule: When you draw the first TGraph in a pad, include "A" in the options if you want ROOT to create axes based on the graph’s range. If you forget "A" on the first draw, you may see nothing or re use old axes.

Overlays and the `SAME` Option

Overlaying multiple objects is extremely common. The single most important drawing option for this is "SAME".

General patterns:

  1. Draw the first object without "SAME", so ROOT creates axes:
cpp
h1->Draw("E1");          // Data histogram with errors
  1. Draw subsequent objects with "SAME":
cpp
h2->Draw("HIST SAME");   // Overlay MC histogram as line
f->Draw("SAME");         // Overlay a TF1 fit on the same axes

For graphs, the first one usually has "A":

cpp
g1->Draw("APL");         // Axes + line + points
g2->Draw("PL SAME");     // Overlay without modifying axes

You can also combine "SAME" with 2D options:

cpp
h2->Draw("COLZ");        // Main color map
h_cont->Draw("CONT3 SAME"); // Overlaid contour lines

Common pitfall: Mixing histogram and graph axes. If you draw a histogram first, then draw a TGraph without "SAME", the graph will erase the histogram and use its own axes. Always remember "SAME" for overlays.

Axes, Log Scales, and Pad Settings

While not strictly drawing options passed to Draw(), pad and axis settings control how the drawing appears.

Key methods on TCanvas or TPad:

MethodEffect
pad->SetLogx(1);Use logarithmic scale on the X axis.
pad->SetLogy(1);Use logarithmic scale on the Y axis.
pad->SetLogz(1);Use logarithmic scale on the Z axis (color scale).
pad->SetGridx(1);Draw a grid on X.
pad->SetGridy(1);Draw a grid on Y.

Examples:

cpp
TCanvas *c = new TCanvas("c", "log plot", 800, 600);
c->SetLogy(1);
h->Draw("HIST");

Axis-only options with histograms:

cpp
h->Draw("AXIS");      // Only axes, no content

This is useful when you want to draw custom objects but still rely on histogram style axes.

Important rule: Logarithmic scales require all plotted values on that axis to be strictly positive. If your histogram has bins with zero or negative contents on a log axis, they will not be visible or may produce warnings.

Function Drawing Options (TF1, TF2)

Functions (TF1, TF2) also use drawing options, though they are more limited and mostly related to line style or overlaying.

OptionEffect
(empty string)Default line drawing of the function.
"SAME"Draw function on top of existing content without erasing.
"L"Line style, often default for TF1.
"C"Smooth curve using a cubic spline approximation.
"AXIS"Draw only function axes.
"NORM"Draw the normalized function (for some contexts).

Examples:

cpp
f->Draw();                // Standalone function with axes
h->Draw("HIST");
f->Draw("SAME");          // Overlay function on histogram

When fitting histograms or graphs, ROOT automatically draws the TF1 with SAME relative to the object that was fitted.

Important rule: When you fit a histogram or graph, the fit function is created and drawn using the same pad and axes as the object. You usually do not need to call Draw() on the fit function explicitly unless you want to re draw it separately.

Combining Options

Multiple options are very often combined in one string. ROOT will interpret each letter or keyword and apply them together.

Some common combined patterns:

Option stringTypical use
"HIST SAME"Overlay histogram as line.
"E1 SAME"Overlay points with error bars.
"TEXT COLZ"Show numbers on a 2D color map.
"AP"First graph with axes, points only.
"ALP"First graph with axes, line, and points.
"APLE"First error graph with axes, line, points, error bars.

Order inside the string does not usually matter, as long as you do not split multi character tokens. For example "COLZ TEXT" and "TEXT COLZ" both work, but "CO LZ" would not.

Important rule: Multi letter options such as "COLZ", "HIST", "SURF", and "LEGO" must appear exactly as written, without spaces, and in the correct case.

Quick Reference Summary

The following compact tables summarize the most frequently used drawing options.

Most common 1D histogram options:

PurposeSuggested option
Basic histogram"" or "HIST"
Data with errors"E1"
Overlay another histogram"HIST SAME"
Overlay data on MCMC: "HIST", Data: "E1 SAME"
Show bin numbers"TEXT"

Most common 2D histogram options:

PurposeSuggested option
Color map"COLZ"
Contours"CONT4Z"
3D lego plot"LEGO2"
Numbers on cells"TEXT COLZ"

Most common graph and error graph options:

PurposeSuggested option
First simple graph"AP"
First graph with line"ALP"
Error graph, first draw"APLE" or "APE"
Overlay graph"P SAME" or "PL SAME"
Overlay error graph"PE SAME"

With these options, you can cover most everyday plotting tasks in ROOT. For more exotic combinations or rare options, the ROOT class reference for TH1, TH2, and TGraph provides the full list.

Views: 12

Comments

Please login to add a comment.

Don't have an account? Register now!