Skip to content

Commit

Permalink
[tutorials] Rename and comment and modernise graphs tutorials.
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel P. Astudillo <[email protected]>
Co-authored-by: Emanuele Chiamulera <[email protected]>
  • Loading branch information
3 people authored and martamaja10 committed Jan 9, 2025
1 parent bb00507 commit 7793a83
Show file tree
Hide file tree
Showing 59 changed files with 1,434 additions and 251 deletions.
4 changes: 2 additions & 2 deletions documentation/users-guide/Graphs.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ gStyle->SetEndErrorSize(np);
The four parameters of **`TGraphErrors`** are: `X, Y` (as in
**`TGraph`**), `X`-errors, and `Y`-errors - the size of the errors
in the `x` and `y` direction. Next example is
`$ROOTSYS/tutorials/visualisation/graphs/gerrors.C.`
`$ROOTSYS/tutorials/visualisation/graphs/gr002_err_1gr.C.`

``` {.cpp}
{
Expand Down Expand Up @@ -702,7 +702,7 @@ root[] gr5->Draw("ALP")
```

For more graph examples see the scripts: `$ROOTSYS/tutorials` directory
`graph.C`, `gerrors.C`, `zdemo.C`, and `gerrors2.C`.
`gr001_basic.C`, `gr002_err_1gr.C`, `gr303_zdemo.C`, and `gr003_err_2gr.C`.

![A graph with axis titles](pictures/0300005D.png)

Expand Down
4 changes: 2 additions & 2 deletions graf2d/gpad/src/TButton.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void but() {
but3->Draw();
// Create last button with no name. Instead a graph is draw inside the button
// Clicking on this button will invoke the macro $ROOTSYS/tutorials/visualisation/graphs/graph.C
button = new TButton("",".x tutorials/visualisation/graphs/graph.C",0.15,0.15,0.85,0.38);
// Clicking on this button will invoke the macro $ROOTSYS/tutorials/visualisation/graphs/gr001_basic.C
button = new TButton("",".x tutorials/visualisation/graphs/gr001_basic.C",0.15,0.15,0.85,0.38);
button->SetFillColor(42);
button->Draw();
button->SetEditable(kTRUE);
Expand Down
2 changes: 1 addition & 1 deletion graf2d/gpad/src/TControlBar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ will return the name of the last clicked button.
"A Simple Fitting Example");
bar.AddButton("draw2dopt", ".x hist/draw2dopt.C",
"Drawing Options for 2D Histograms");
bar.AddButton("graph", ".x graphs/graph.C",
bar.AddButton("graph", ".x graphs/gr001_basic.C",
"Examples of a simple graph");
bar.AddButton("tornado", ".x graphics/tornado.C",
"Examples of 3-D PolyMarkers");
Expand Down
2 changes: 1 addition & 1 deletion graf2d/gviz/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
\ingroup Graphics2D
\brief Interface to the graphing package `graphviz`

- graphstruct.C is an example of the graphviz interface classes usage.
- gr016_struct.C is an example of the graphviz interface classes usage.

2 changes: 1 addition & 1 deletion graf2d/gviz/src/TGraphStruct.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ three classes:
a TGraphStruct.
Begin_Macro(source)
../../../tutorials/visualisation/graphs/graphstruct.C
../../../tutorials/visualisation/graphs/gr016_struct.C
End_Macro
A graph structure can be dumped into a "dot" file using DumpAsDotFile.
Expand Down
2 changes: 1 addition & 1 deletion hist/hist/src/TGraphSmooth.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ClassImp(TGraphSmooth);
/** \class TGraphSmooth
\ingroup Graphs
A helper class to smooth TGraph.
see examples in $ROOTSYS/tutorials/visualisation/graphs/motorcycle.C and approx.C
see examples in $ROOTSYS/tutorials/visualisation/graphs/gr010_approx_smooth.C and $ROOTSYS/tutorials/visualisation/graphs/gr015_smooth.C
*/

TGraphSmooth::TGraphSmooth()
Expand Down
2 changes: 1 addition & 1 deletion hist/hist/src/TGraphTime.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ClassImp(TGraphTime);
TGraphTime is used to draw a set of objects evolving with nsteps in time between tmin and tmax.
Each time step has a new list of objects. This list can be identical to
the list of objects in the previous steps, but with different attributes.
see example of use in $ROOTSYS/tutorials/visualisation/graphs/gtime.C
See example of use in $ROOTSYS/tutorials/visualisation/graphs/gr017_time.C
*/

////////////////////////////////////////////////////////////////////////////////
Expand Down
4 changes: 2 additions & 2 deletions hist/hist/src/TMultiGraph.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ Automatic coloring according to the current palette is available as shown in the
following example:
Begin_Macro(source)
../../../tutorials/visualisation/graphs/multigraphpalettecolor.C
../../../tutorials/visualisation/graphs/gr105_multigraphpalettecolor.C
End_Macro
\anchor MG01f
Expand Down Expand Up @@ -324,7 +324,7 @@ overlap. The following example shows how to make them all visible.
Begin_Macro(source)
../../../tutorials/visualisation/graphs/multigraph.C
../../../tutorials/visualisation/graphs/gr007_multigraph.C
End_Macro
\anchor MG03
Expand Down
2 changes: 1 addition & 1 deletion hist/hist/src/TScatter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ color map and the fourth on the marker size.
The following example demonstrates how it works:
Begin_Macro(source)
../../../tutorials/visualisation/graphs/scatter.C
../../../tutorials/visualisation/graphs/gr006_scatter.C
End_Macro
### TScatter's plotting options
Expand Down
4 changes: 2 additions & 2 deletions hist/histpainter/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
The histograms and graphs plotting options are described in details in the THistPainter and TGraphPainter classes.
Some related tutorials:

- graph.C: Using and drawing a simple TGraph.
- graph2derrorsfit.C: TGraph2D with errors drawing.
- gr001_basic.C: Using and drawing a simple TGraph.
- gr011_2Derrorsfit.C: TGraph2D with errors drawing.
- h1draw.C: Drawing Options for 1D Histograms.
- hbars.C: Demo of option bar with histograms.
- hsimple.C: Simple drawing of a 1D Histograms.
Expand Down
12 changes: 6 additions & 6 deletions hist/histpainter/src/TGraphPainter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ case the line width number is interpreted as:
The current fill area attributes are used to draw the hatched zone.
Begin_Macro(source)
../../../tutorials/visualisation/graphs/exclusiongraph.C
../../../tutorials/visualisation/graphs/gr106_exclusiongraph.C
End_Macro
\anchor GrP3
Expand Down Expand Up @@ -530,11 +530,11 @@ is determined according to the number of objects having palette coloring in
the current pad.
Begin_Macro(source)
../../../tutorials/visualisation/graphs/graphpalettecolor.C
../../../tutorials/visualisation/graphs/gr104_palettecolor.C
End_Macro
Begin_Macro(source)
../../../tutorials/visualisation/graphs/multigraphpalettecolor.C
../../../tutorials/visualisation/graphs/gr105_multigraphpalettecolor.C
End_Macro
\anchor GrP6
Expand Down Expand Up @@ -633,18 +633,18 @@ graphically. Point will be highlighted as "point circle" (presented by
marker object). Moreover, any highlight (change of point) emits signal
`TCanvas::Highlighted()` which allows the user to react and call their own
function. For a better understanding please see also the tutorials
`$ROOTSYS/tutorials/visualisation/graphs/hlGraph*.C` files.
`$ROOTSYS/tutorials/visualisation/graphs/gr*_highlight*.C` files.
Highlight mode is switched on/off by `TGraph::SetHighlight()` function
or interactively from `TGraph` context menu. `TGraph::IsHighlight()` to verify
whether the highlight mode enabled or disabled, default it is disabled.
~~~ {.cpp}
root [0] .x $ROOTSYS/tutorials/visualisation/graphs/gerrors2.C
root [0] .x $ROOTSYS/tutorials/visualisation/graphs/gr003_err_2gr.C
root [1] // try SetHighlight() interactively from TGraph context menu
~~~
\image html hlgerrors2.gif "Highlight mode for graph"
\image html hl_gr003_err_2gr.gif "Highlight mode for graph"
See how it is used
<a href="classTHistPainter.html#HP30a">highlight mode and user function</a>
Expand Down
4 changes: 2 additions & 2 deletions test/stressGUI.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2211,8 +2211,8 @@ void testControlBars()
bar->AddButton("fit1", ".x fit/fit1.C", "A Simple Fitting Example");
bar->AddButton("multifit", ".x fit/multifit.C", "Fitting in Subranges of Histograms");
bar->AddButton("h1draw", ".x hist/h1draw.C", "Drawing Options for 1D Histograms");
bar->AddButton("graph", ".x graphs/graph.C", "Example of a Simple Graph");
bar->AddButton("gerrors", ".x graphs/gerrors.C", "Example of a Graph with Error Bars");
bar->AddButton("graph", ".x graphs/gr001_graph.C", "Example of a Simple Graph");
bar->AddButton("gerrors", ".x graphs/gr002_err_1gr.C", "Example of a Graph with Error Bars");
bar->AddButton("tornado", ".x graphics/tornado.C", "Examples of 3-D PolyMarkers");
bar->AddButton("shapes", ".x geom/shapes.C", "The Geometry Shapes");
bar->AddButton("geometry", ".x geom/geometry.C", "Creation of the NA49 Geometry File");
Expand Down
10 changes: 5 additions & 5 deletions tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if (NOT dataframe)
# RDataFrame
list(APPEND dataframe_veto analysis/dataframe/*.C analysis/dataframe/*.py)
# RDataFrame tutorial in graphs
list(APPEND dataframe_veto visualisation/graphs/timeSeriesFromCSV_TDF.C)
list(APPEND dataframe_veto visualisation/graphs/gr109_timeSeriesFromCSV_TDF.C)
# TMVA tutorials dependent on RDataFrame
list(APPEND dataframe_veto machine_learning/tmva*.C)
list(APPEND dataframe_veto machine_learning/TMVA_SOFIE_RDataFrame*.C)
Expand Down Expand Up @@ -244,7 +244,7 @@ if(NOT ROOT_opengl_FOUND)
endif()

if(NOT GRAPHVIZ_FOUND)
set(gviz_veto visualisation/graphs/graphstruct.C)
set(gviz_veto visualisation/graphs/gr016_struct.C)
endif()

if(NOT TBB_FOUND AND NOT builtin_tbb)
Expand Down Expand Up @@ -443,7 +443,7 @@ if(MSVC AND NOT llvm13_broken_tests)
list(APPEND extra_veto
analysis/dataframe/df007_snapshot.C
visualisation/graphics/earth.C
visualisation/graphs/motorcycle.C
visualisation/graphs/gr015_smooth.C
io/ntuple/ntpl001_staff.C)
endif()
endif()
Expand Down Expand Up @@ -511,8 +511,8 @@ set(returncode_1 math/fit/fit2a.C
visualisation/graphics/earth.C
visualisation/graphics/pavetext.C
visualisation/graphics/tmathtext.C visualisation/graphics/tmathtext2.C
visualisation/graphs/exclusiongraph.C
visualisation/graphs/graphstruct.C
visualisation/graphs/gr106_exclusiongraph.C
visualisation/graphs/gr016_struct.C
hist/ContourList.C
hist/hist006_TH1_bar_charts.C
hist/th2polyBoxes.C
Expand Down
4 changes: 2 additions & 2 deletions tutorials/demos.C
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void demos() {
bar->AddButton("fit1", ".x math/fit/fit1.C", "A Simple Fitting Example");
bar->AddButton("multifit", ".x math/fit/multifit.C", "Fitting in Subranges of Histograms");
bar->AddButton("h1ReadAndDraw", ".x hist/h1ReadAndDraw.C", "Drawing Options for 1D Histograms");
bar->AddButton("graph", ".x visualisation/graphs/graph.C", "Example of a Simple Graph");
bar->AddButton("gerrors", ".x visualisation/graphs/gerrors.C", "Example of a Graph with Error Bars");
bar->AddButton("graph", ".x visualisation/graphs/gr001_basic.C", "Example of a Simple Graph");
bar->AddButton("gerrors", ".x visualisation/graphs/gr002_err_1gr.C", "Example of a Graph with Error Bars");
bar->AddButton("tornado", ".x visualisation/graphics/tornado.C", "Examples of 3-D PolyMarkers");
bar->AddButton("geometry", ".x visualisation/geom/rootgeom.C", "Example of TGeoManager drawing");
bar->AddButton("file", ".x io/file.C", "The ROOT File Format");
Expand Down
12 changes: 6 additions & 6 deletions tutorials/legacy/benchmarks.C
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ void benchmarks() {
summary->AddText(" hist/fillrandom.C");
summary->AddText(" fit/fit1.C");
summary->AddText(" hist/h1ReadAndDraw.C");
summary->AddText(" graphs/graph.C");
summary->AddText(" graphs/gerrors.C");
summary->AddText(" graphs/gr001_basic.C");
summary->AddText(" graphs/gr002_err_1gr.C");
summary->AddText(" graphics/tornado.C");
summary->AddText(" graphs/surfaces.C");
summary->AddText(" graphs/zdemo.C");
summary->AddText(" graphs/gr303_zdemo.C");
summary->AddText(" geom/geometry.C");
summary->AddText(" geom/na49view.C");
summary->AddText(" tree/ntuple1.C");
Expand All @@ -60,11 +60,11 @@ void benchmarks() {
bexec(dir,"hist/fillrandom.C");
bexec(dir,"fit/fit1.C");
bexec(dir,"hist/h1ReadAndDraw.C");
bexec(dir,"graphs/graph.C");
bexec(dir,"graphs/gerrors.C");
bexec(dir,"graphs/gr001_basic.C");
bexec(dir,"graphs/gr002_err_1gr.C");
bexec(dir,"graphics/tornado.C");
bexec(dir,"graphs/surfaces.C");
bexec(dir,"graphs/zdemo.C");
bexec(dir,"graphs/gr303_zdemo.C");
bexec(dir,"geom/geometry.C");
bexec(dir,"geom/na49view.C");
bexec(dir,"tree/ntuple1.C");
Expand Down
20 changes: 20 additions & 0 deletions tutorials/visualisation/graphs/data_basic.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-3.000000 -0.989992
-2.684211 -0.897212
-2.368421 -0.715699
-2.052632 -0.463406
-1.736842 -0.165284
-1.421053 0.149185
-1.105263 0.448899
-0.789474 0.704219
-0.473684 0.889894
-0.157895 0.987561
0.157895 0.987561
0.473684 0.889894
0.789474 0.704219
1.105263 0.448899
1.421053 0.149185
1.736842 -0.165284
2.052632 -0.463406
2.368421 -0.715699
2.684211 -0.897212
3.000000 -0.989992
File renamed without changes.
37 changes: 37 additions & 0 deletions tutorials/visualisation/graphs/gr002_err_1gr.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// \file
/// \ingroup tutorial_graphs
/// \notebook -js
/// Create and draw a graph with error bars. If more graphs are needed, see the
/// [gr03_err2gr.C](https://root.cern/doc/master/gerrors2_8C.html) tutorial
///
/// See the [TGraphErrors documentation](https://root.cern/doc/master/classTGraphErrors.html)
///
/// \macro_image
/// \macro_code
/// \author Rene Brun

void gr002_err_1gr() {
TCanvas *c1 = new TCanvas("c1","A Simple Graph with error bars",200,10,700,500);

c1->SetGrid();
c1->GetFrame()->SetBorderSize(12);

// We will use the constructor requiring: the number of points, arrays containing the x-and y-axis values, and arrays with the x- andy-axis errors
const Int_t n = 10;
Float_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
Float_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
Float_t ex[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
Float_t ey[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};

// If all x-axis errors should zero, just provide a single 0 in place of ex
TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey);

gr->SetTitle("TGraphErrors Example");
gr->SetMarkerColor(4);
gr->SetMarkerStyle(21);

// To draw in a new/empty canvas or pad, include the option "A" so that the axes are drawn (leave it out if the graph is to be drawn on top of an existing plot
gr->Draw("ALP");

c1->Update();
}
53 changes: 53 additions & 0 deletions tutorials/visualisation/graphs/gr003_err_2gr.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/// \file
/// \ingroup tutorial_graphs
/// \notebook -js
/// Create and draw two graphs with error bars, superposed on the same canvas
///
/// We first draw an empty frame with the axes, then draw the graphs on top of it
/// Note that the graphs should have the same or very close ranges (in both axis),
/// otherwise they may not be visible in the frame.
///
/// Alternatively, an automatic axis scaling can be achieved via a
/// [TMultiGraph](https://root.cern/doc/master/classTMultiGraph.html)
///
/// See the [TGraphErrors documentation](https://root.cern/doc/master/classTGraphErrors.html)
///
/// \macro_image
/// \macro_code
/// \author Rene Brun

void gr003_err_2gr() {
TCanvas *c1 = new TCanvas("c1","2 graphs with errors",200,10,700,500);
c1->SetGrid();

// draw a frame to define the range
TH1F *hr = c1->DrawFrame(-0.4,0,1.2,12);
hr->SetXTitle("X title");
hr->SetYTitle("Y title");
c1->GetFrame()->SetBorderSize(12);

// create first graph
// We will use the constructor requiring: the number of points, arrays containing the x-and y-axis values, and arrays with the x- andy-axis errors
const Int_t n1 = 10;
Double_t xval1[] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
Double_t yval1[] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
// If all x-axis errors should zero, just provide a single 0 in place of ex1
TGraphErrors *gr1 = new TGraphErrors(n1,xval1,yval1,ex1,ey1);
gr1->SetMarkerColor(kBlue);
gr1->SetMarkerStyle(21);
// Since we already have a frame in the canvas, we draw the graph without the option "A" (which draws axes for this graph)
gr1->Draw("LP");

// create second graph
const Int_t n2 = 10;
Float_t xval2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01};
Float_t yval2[] = {0.82,3.86,7,9,10,10.55,9.64,7.26,5.42,2};
Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04};
Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7};
TGraphErrors *gr2 = new TGraphErrors(n2,xval2,yval2,ex2,ey2);
gr2->SetMarkerColor(kRed);
gr2->SetMarkerStyle(20);
gr2->Draw("LP");
}
31 changes: 31 additions & 0 deletions tutorials/visualisation/graphs/gr004_err_asym.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// \file
/// \ingroup tutorial_graphs
/// \notebook
///
/// This tutorial demonstrates the use of TGraphAsymmErrors to plot a graph with asymmetrical errors on both the x and y axes.
/// The errors for the x values are divided into low (left side of the marker) and high (right side of the marker) errors.
/// Similarly, for the y values, there are low (lower side of the marker) and high (upper side of the marker) errors.
///
/// \macro_image
/// \macro_code
///
/// \author Miro Helbich

void gr004_err_asym() {
TCanvas *c2 = new TCanvas("c2","", 700, 500);

c2->SetGrid();
const Int_t npoints=3;
Double_t xaxis[npoints] = {1.,2.,3.};
Double_t yaxis[npoints] = {10.,20.,30.};

Double_t exl[npoints] = {0.5,0.2,0.1}; //Lower x errors
Double_t exh[npoints] = {0.5,0.3,0.4}; //Higher x errors
Double_t eyl[npoints] = {3.,5.,4.}; //Lower y errors
Double_t eyh[npoints] = {3.,5.,4.}; //Higher y errors

TGraphAsymmErrors *gr = new TGraphAsymmErrors(npoints,xaxis,yaxis,exl,exh,eyl,eyh); //Create the TGraphAsymmErrors object with data and asymmetrical errors

gr->SetTitle("A simple graph with asymmetrical errors");
gr->Draw("A*"); //"A" = draw axes and "*" = draw markers at the points with error bars
}
Loading

0 comments on commit 7793a83

Please sign in to comment.