Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches

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.

Tutorials sorted after groups

List of all tutorials

Basics

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.

Formatting

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.

Intermediate

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.

More tutorials

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
  View in nbviewer Open in SWAN
This tutorial demonstrates how to create simple graphs in ROOT.
 
file  gr002_errors.C
  View in nbviewer Open in SWAN
Create and draw a graph with error bars.
 
file  gr003_errors2.C
  View in nbviewer Open in SWAN
Create and draw two graphs with error bars, superposed on the same canvas
 
file  gr004_errors_asym.C
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
A macro to demonstrate the functionality of TGraph::Apply() method.
 
file  gr006_scatter.C
  View in nbviewer Open in SWAN
Draw a scatter plot for 4 variables, mapped to: x, y, marker colour and marker size.
 
file  gr007_multigraph.C
  View in nbviewer Open in SWAN
TMultiGraph is used to combine multiple graphs into one plot.
 
file  gr008_multierrors.C
  View in nbviewer Open in SWAN
Draw a graph with multiple errors.
 
file  gr009_bent_err.C
  View in nbviewer Open in SWAN
Graph with bent error bars.
 
file  gr009_bent_err.py
  View in nbviewer Open in SWAN
Graph with bent error bars.
 
file  gr010_approx_smooth.C
  View in nbviewer Open in SWAN
Create a TGraphSmooth and show the usage of the interpolation function Approx.
 
file  gr011_graph2d_errorsfit.C
  View in nbviewer Open in SWAN
Create, draw and fit a TGraph2DErrors.
 
file  gr012_polar.C
  View in nbviewer Open in SWAN
Create and draw a polar graph.
 
file  gr013_polar2.C
  View in nbviewer Open in SWAN
Create and draw a polar graph with errors and polar axis in radians (PI fractions).
 
file  gr014_polar3.C
  View in nbviewer Open in SWAN
Create a polar graph using a TF1 and draw it with PI axis.
 
file  gr015_smooth.C
  View in nbviewer Open in SWAN
Show scatter plot smoothers: ksmooth, lowess, supsmu, as described in: Modern Applied Statistics with S-Plus, 3rd Edition W.N.
 
file  gr016_struct.C
  View in nbviewer Open in SWAN
Draw a simple graph structure.
 
file  gr017_time.C
  View in nbviewer Open in SWAN
Example of TGraphTime.
 
file  gr018_time2.C
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
Show how to shade an area between two graphs.
 
file  gr102_reverse_graph.C
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
Draw three graphs with an exclusion zone.
 
file  gr107_exclusiongraph2.C
  View in nbviewer Open in SWAN
Draw several graphs with exclusion zones.
 
file  gr108_timeSeriesFromCSV.C
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
This tutorial demonstrates how to set a logarithmic scale for the axes of a graph using the SetLogScale() method.
 
file  gr111_legend.C
  View in nbviewer Open in SWAN
Simple graph with legend.
 
file  gr112_reverse_graph_and_errors.C
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
Draw spherical waves interference.
 
file  gr202_textmarkers.C
  View in nbviewer Open in SWAN
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
  View in nbviewer Open in SWAN
This macro is an example of graphs in log scales with annotations.