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 | Create a simple graph from available data or from a file, and draw it. | |
gr002_errors.C | Create and draw a graph with error bars. | |
gr003_errors2.C | Create and draw two graphs with error bars, superposed on the same canvas (not using TMultiGraph). | |
gr004_errors_asym.C | Create and draw a graph with asymmetric x & y errors. | |
gr005_apply.C | Demonstrate the functionality of the TGraph::Apply() method. | |
gr006_scatter.C | Scatter plot for 4 variables, mapped to: x, y, marker color and marker size. | |
gr007_multigraph.C | 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 | Create a TGraphSmooth and show the usage of the interpolation function Approx. | |
gr011_graph2d_errorsfit.C | Create, draw and fit a TGraph2DErrors. | |
gr012_polar.C | Create and draw a polar graph. | |
gr013_polar2.C | Polar graph with errors and polar axis in radians (PI fractions). | |
gr014_polar3.C | 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 |
![]() ![]() ![]() | |
file | gr002_errors.C |
![]() ![]() ![]() | |
file | gr003_errors2.C |
![]() ![]() ![]() | |
file | gr004_errors_asym.C |
![]() ![]() ![]() | |
file | gr005_apply.C |
![]() ![]() ![]() | |
file | gr006_scatter.C |
![]() ![]() ![]() | |
file | gr007_multigraph.C |
![]() ![]() ![]() | |
file | gr008_multierrors.C |
![]() ![]() ![]() | |
file | gr009_bent_err.C |
![]() ![]() ![]() | |
file | gr009_bent_err.py |
![]() ![]() Graph with bent error bars. | |
file | gr010_approx_smooth.C |
![]() ![]() ![]() | |
file | gr011_graph2d_errorsfit.C |
![]() ![]() ![]() | |
file | gr012_polar.C |
![]() ![]() ![]() | |
file | gr013_polar2.C |
![]() ![]() ![]() | |
file | gr014_polar3.C |
![]() ![]() ![]() | |
file | gr015_smooth.C |
![]() ![]() ![]() | |
file | gr016_struct.C |
![]() ![]() Draw a simple graph structure. | |
file | gr017_time.C |
![]() ![]() ![]() | |
file | gr018_time2.C |
![]() ![]() ![]() | |
file | gr101_shade_area.C |
![]() ![]() ![]() | |
file | gr102_reverse_graph.C |
![]() ![]() ![]() | |
file | gr103_zones.C |
![]() ![]() ![]() | |
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 |
![]() ![]() ![]() | |
file | gr105_multigraphpalettecolor.C |
![]() ![]() ![]() | |
file | gr106_exclusiongraph.C |
![]() ![]() ![]() | |
file | gr107_exclusiongraph2.C |
![]() ![]() ![]() | |
file | gr108_timeSeriesFromCSV.C |
![]() ![]() ![]() | |
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 |
![]() ![]() ![]() | |
file | gr110_logscale.C |
![]() ![]() ![]() SetLogScale() method. | |
file | gr111_legend.C |
![]() ![]() ![]() | |
file | gr112_reverse_graph_and_errors.C |
![]() ![]() ![]() | |
file | gr201_waves.C |
![]() ![]() ![]() | |
file | gr202_textmarkers.C |
![]() ![]() ![]() | |
file | gr301_highlight1.C |
![]() | |
file | gr302_highlight2.C |
![]() | |
file | gr303_zdemo.C |
![]() ![]() ![]() | |