Examples showing the "graphs classes" usage.
A TGraph is an object made of two arrays X and Y with n points each. ROOT can create TGraphs automatically by reading a text file (e.g. CSV), using a function, another TGraph, histogram, vectors, arrays, or even by adding pairs of points one by one.
In addition, ROOT offers multiple variations to basic TGraphs, such as:
TGraphs are painted through the TGraphPainter or TGraph2DPainter classes. As a general remark, TGraphs are not binned, each point is painted individually.
The graph tutorials below are divided in groups of increasing complexity, starting with examples showing how to create, fill, and draw the different types of graphs.
These examples showcase the creation of different types of graphs and basic ways to plot them.
| Tutorial | Description | |
|---|---|---|
| gr001_simple.C | gr001_simple.py | Create a simple graph from available data or from a file, and draw it. |
| gr002_errors.C | gr002_errors.py | Create and draw a graph with error bars. |
| gr003_errors2.C | gr003_errors2.py | Create and draw two graphs with error bars, superposed on the same canvas (not using TMultiGraph). |
| gr004_errors_asym.C | gr004_errors_asym.py | Create and draw a graph with asymmetric x & y errors. |
| gr005_apply.C | gr005_apply.py | Demonstrate the functionality of the TGraph::Apply() method. |
| gr006_scatter.C | gr006_scatter.py | Scatter plot for 4 variables, mapped to: x, y, marker color and marker size. |
| gr007_multigraph.C | gr007_multigraph.py | Create and draw a TMultiGraph (several graphs superposed). |
| gr008_multierrors.C | Graph with multiple y errors in each bin. | |
| gr009_bent_err.C | gr009_bent_err.py | Graph with bent (non-vertical/non-horizontal) error bars. |
| gr010_approx_smooth.C | gr010_approx_smooth.py | Create a TGraphSmooth and show the usage of the interpolation function Approx. |
| gr011_graph2d_errorsfit.C | gr011_graph2d_errorsfit.py | Create, draw and fit a TGraph2DErrors. |
| gr012_polar.C | gr012_polar.py | Create and draw a polar graph. |
| gr013_polar2.C | gr013_polar2.py | Polar graph with errors and polar axis in radians (PI fractions). |
| gr014_polar3.C | gr014_polar3.py | Create a polar graph using a TF1 and draw it with PI axis. |
| gr015_smooth.C | Show scatter plot smoothers: ksmooth, lowess, supsmu | |
| gr016_struct.C | Draw a simple graph structure. | |
| gr017_time.C | Example of TGraphTime. | |
| gr018_time2.C | TGraphTime to visualize a set of particles with their time stamp in a MonteCarlo program. | |
These examples show different ways of formatting the graphs, in particular how to:
| Tutorial | Description | |
|---|---|---|
| gr101_shade_area.C | Shade an area between two graphs. | |
| gr102_reverse_graph.C | Reverse points of a graph along x. | |
| gr103_zones.C | gr103_zones.py | Divide a canvas into adjacent subpads, with axis labels on the top and right side of the pads. |
| gr104_palettecolor.C | Automatically set graph colors from a palette. | |
| gr105_multigraphpalettecolor.C | Automatically set multi-graph colors from a palette. | |
| gr106_exclusiongraph.C | Draw three graphs (in a TMultiGraph) with exclusion zones. | |
| gr107_exclusiongraph2.C | Draw graphs (superposed, but no TMultiGraph) with exclusion zones. | |
| gr108_timeSeriesFromCSV.C | gr108_timeSeriesFromCSV.py | Use of the time axis on a TGraph with data read from a text file. |
| gr109_timeSeriesFromCSV_RDF.C | Use of the time axis on a TGraph with data read from a text file, but using RDataFrame. | |
| gr110_logscale.C | Set logarithmic scale for the axes of the graph. | |
| gr111_legend.C | Add a legend. | |
| gr112_reverse_graph_and_errors.C | Reverse points of the graph along both axes - examples with various error types. | |
These examples are slightly more advanced so will be most useful for more advanced users.
| Tutorial | Description |
|---|---|
| gr201_waves.C | Draw spherical waves interference, using closed and filled TGraphs to hide other plot elements. |
| gr202_textmarkers.C | Draw a graph with text attached to each point. Uses a TExec function to attach the text to the points. |
These examples show the most complex usage of the graphs functionality.
| Tutorial | Description |
|---|---|
| gr301_highlight1.C | How to use the interactive highlight mode on graph, thanks to the TCanvas HighlightConnect method. |
| gr302_highlight2.C | How to use the interactive highlight mode on graph, thanks to the TCanvas HighlightConnect method. |
| gr303_zdemo.C | Example of graphs in log scales with annotations and other advanced plot formatting. |
Files | |
| file | gr001_simple.C |
This tutorial demonstrates how to create simple graphs in ROOT. | |
| file | gr001_simple.py |
This tutorial demonstrates how to create simple graphs in ROOT. | |
| file | gr002_errors.C |
Create and draw a graph with error bars. | |
| file | gr002_errors.py |
Create and draw a graph with error bars. | |
| file | gr003_errors2.C |
Create and draw two graphs with error bars, superposed on the same canvas | |
| file | gr003_errors2.py |
Create and draw two graphs with error bars, superposed on the same canvas | |
| file | gr004_errors_asym.C |
This tutorial demonstrates the use of TGraphAsymmErrors to plot a graph with asymmetrical errors on both the x and y axes. | |
| file | gr004_errors_asym.py |
This tutorial demonstrates the use of TGraphAsymmErrors to plot a graph with asymmetrical errors on both the x and y axes. | |
| file | gr005_apply.C |
A macro to demonstrate the functionality of TGraph::Apply() method. | |
| file | gr005_apply.py |
A macro to demonstrate the functionality of TGraph::Apply() method. | |
| file | gr006_scatter.C |
Draw a scatter plot for 4 variables, mapped to: x, y, marker colour and marker size. | |
| file | gr006_scatter.py |
Draw a scatter plot for 4 variables, mapped to: x, y, marker colour and marker size. | |
| file | gr007_multigraph.C |
TMultiGraph is used to combine multiple graphs into one plot. | |
| file | gr007_multigraph.py |
TMultiGraph is used to combine multiple graphs into one plot. | |
| file | gr008_multierrors.C |
Draw a graph with multiple errors. | |
| file | gr009_bent_err.C |
Graph with bent error bars. | |
| file | gr009_bent_err.py |
Graph with bent error bars. | |
| file | gr010_approx_smooth.C |
Create a TGraphSmooth and show the usage of the interpolation function Approx. | |
| file | gr010_approx_smooth.py |
Create a TGraphSmooth and show the usage of the interpolation function Approx. | |
| file | gr011_graph2d_errorsfit.C |
Create, draw and fit a TGraph2DErrors. | |
| file | gr011_graph2d_errorsfit.py |
Create, draw and fit a TGraph2DErrors. | |
| file | gr012_polar.C |
Create and draw a polar graph. | |
| file | gr012_polar.py |
Create and draw a polar graph. | |
| file | gr013_polar2.C |
Create and draw a polar graph with errors and polar axis in radians (PI fractions). | |
| file | gr013_polar2.py |
Create and draw a polar graph with errors and polar axis in radians (PI fractions). | |
| file | gr014_polar3.C |
Create a polar graph using a TF1 and draw it with PI axis. | |
| file | gr014_polar3.py |
Create a polar graph using a TF1 and draw it with PI axis. | |
| file | gr015_smooth.C |
Show scatter plot smoothers: ksmooth, lowess, supsmu, as described in: Modern Applied Statistics with S-Plus, 3rd Edition W.N. | |
| file | gr016_struct.C |
Draw a simple graph structure. | |
| file | gr017_time.C |
Example of TGraphTime. | |
| file | gr018_time2.C |
Example of TGraphTime showing how the class could be used to visualize a set of particles with their time stamp in a MonteCarlo program. | |
| file | gr101_shade_area.C |
Show how to shade an area between two graphs. | |
| file | gr102_reverse_graph.C |
This example tests the reverse graphs obtained with Draw("a pl rx ry ") on a TGraph, where rx and ry refere to the reversing of x and y axis. | |
| file | gr103_zones.C |
Example of script showing how to divide a canvas into adjacent subpads + axis labels on the top and right side of the pads. | |
| file | gr103_zones.py |
Example of script showing how to divide a canvas into adjacent subpads + axis labels on the top and right side of the pads. | |
| file | gr104_palettecolor.C |
Palette coloring for graphs is activated thanks to the options PFC (Palette Fill Color), PLC (Palette Line Color) and AMC (Palette Marker Color). | |
| file | gr105_multigraphpalettecolor.C |
Palette coloring for multi-graphs is activated thanks to the options PFC (Palette Fill Color), PLC (Palette Line Color) and AMC (Palette Marker Color). | |
| file | gr106_exclusiongraph.C |
Draw three graphs with an exclusion zone. | |
| file | gr107_exclusiongraph2.C |
Draw several graphs with exclusion zones. | |
| file | gr108_timeSeriesFromCSV.C |
This macro illustrates the use of the time axis on a TGraph with data read from a text file containing the SWAN usage statistics during July 2017. | |
| file | gr108_timeSeriesFromCSV.py |
This macro illustrates the use of the time axis on a TGraph with data read from a text file containing the SWAN usage statistics during July 2017. | |
| file | gr109_timeSeriesFromCSV_RDF.C |
This macro illustrates the use of the time axis on a TGraph with data read from a text file containing the SWAN usage statistics during July 2017. | |
| file | gr110_logscale.C |
This tutorial demonstrates how to set a logarithmic scale for the axes of a graph using the SetLogScale() method. | |
| file | gr111_legend.C |
Simple graph with legend. | |
| file | gr112_reverse_graph_and_errors.C |
This example tests all the various cases of reverse graphs obtained with Draw("a pl rx ry "), where rx and ry refer to the reversing of x and y axis. | |
| file | gr201_waves.C |
Draw spherical waves interference. | |
| file | gr202_textmarkers.C |
Draw a graph with text attached to each point. | |
| file | gr301_highlight1.C |
This tutorial demonstrates how to use the highlight mode on graph, thanks to the TCanvas HighlightConnect method. | |
| file | gr302_highlight2.C |
This tutorial demonstrates how to use the highlight mode on graph, thanks to the TCanvas HighlightConnect method. | |
| file | gr303_zdemo.C |
This macro is an example of graphs in log scales with annotations. | |