A graph is an object made of two arrays
Y, holding the
y coordinates of n points.
A graph or chart is a set of categorical variables, this is un-binned data.
A histogram is used for continuous data, where the bins represent ranges of data (binned data), see → Fitting histograms.
ROOT provides numerous graph classes, of which the following are among the most used:
- A graph.
- A graph with error bars.
- A TGraph with bent, asymmetric error bars.
- A TGraph with asymmetric error bars and multiple y error dimensions.
- A polar graph including error bars.
- Draws quantile-quantile plots.
- A collection of TGraph (or derived) objects.
- Graph made of three arrays X, Y and Z with the same number of points each.
- A TGraph2D with error bars.
Working with graphs
ROOT supports the general case with non-equidistant points, and the special case with equidistant points.
Creating a graph
Use a graph constructor to create a graph object.
Arrays of coordinates are defined and then graph with the TGraph
constructor is created.
The coordinates can be arrays of doubles or floats.
Drawing a graph
- Use the
Draw()method to draw a graph.
The TGraphPainter class implements all drawing options.
Figure: Graph drawn with Draw().
The drawing options are not case sensitive.
For detailed information on the drawing options for graph classes, refer to TGraphPainter .
L: A simple poly-line between every point is drawn.
F: A filled area is drawn.
F1: As F, but the filled area is no more repartee around X=0 or Y=0.
F2: Draws a filled area poly line connecting the center of bins.
A: Axis are drawn around the graph.
C: A smooth curve is drawn.
* A star is plotted at each point.
P: The current marker of the graph is plotted at each point.
B: A bar chart is drawn at each point.
Figure: Graph drawn with Draw(“AL*”).
Setting titles for a graph
Before giving the axis of a graph a title you need to draw the graph first.
You can set the title by getting the axis and calling the TGraph::SetTitle() method.
You can use the TAxis::CenterTitle method to center the title.
y are defined. Then the titles of the
y axes are set as follows:
Zooming a graph
To zoom a graph you can create a histogram with the desired axis range first. Draw the empty histogram and then draw the graph using the existing axis from the histogram.
Figure: A zoomed graph.
- Use the graph
Fit()methods (for example TGraph::Fit()), for fitting graphs.
For more information on the
Fit() method, → see Fitting histograms.
Graphs with error bars
with error bars.
The TGraphPainter class implements all drawing options for graphs with error bars.
Figure: Graph with error bars.
- Use TMultiGraph::Add() to add a new graph to the list.
Figure: Graph with error bars.
graph is a graphics object that is made of three arrays
Z with the same number of points each.
The TGraph2D class has the following constructors:
- With a dimension n of an array and three arrays
z(can be arrays of doubles, floats, or integers).
- With only the dimension n of an array.
- Internal arrays are filled with the
SetPoint()method at the position
iwith the values
- Without parameters. Use the
SetPoint()method to fill the internal arrays.
- From a file. The arrays are read from the ASCII file, for example
graph.dataccording to a specified format. The format’s default value is
%lg %lg %lg.
Note that in any of last three cases, you can use the
SetPoint() method to change a data point or to add
a new one. If the data point index
(i) is greater than the size of the internal arrays, they are automatically extended.
You can draw a TGraph2D with any drawing option valid for 2D histogram drawing. In this case, an intermediate 2D histogram is filled using the Delaunay triangles technique to interpolate the data set.
You can also use the following specific drawing options for TGraph2D graphs:
TRI: Delaunay triangles are drawn using the filled area. A hidden surface drawing technique is used. The surface is painted with the current fill area color. The edges of the triangles are painted with the current line color.
TRIW: Delaunay triangles are drawn as wire frames.
TRI1: Delaunay triangles are painted with color levels. The edges of the triangles are painted with the current line color.
TRI2: Delaunay triangles are painted with color levels.
P: Draws a marker at each vertex.
P0: Draws a circle at each vertex. Each circle background is white.
Figure: A TGraph2D with the drawing option surf1.