Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tutorials] Rename and comment graphs tutorials #17110

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/graphs/gerrors.C.`
`$ROOTSYS/tutorials/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 @@ -68,8 +68,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/graphs/graph.C
button = new TButton("",".x tutorials/graphs/graph.C",0.15,0.15,0.85,0.38);
// Clicking on this button will invoke the macro $ROOTSYS/tutorials/graphs/gr001_basic.C
button = new TButton("",".x tutorials/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/graphs/graphstruct.C
../../../tutorials/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/graphs/motorcycle.C and approx.C
see examples in gr010_approx_smooth.C and 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/graphs/gtime.C
See example of use in 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/graphs/multigraphpalettecolor.C
../../../tutorials/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/graphs/multigraph.C
../../../tutorials/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/graphs/scatter.C
../../../tutorials/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 @@ -211,7 +211,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/graphs/exclusiongraph.C
../../../tutorials/graphs/gr106_exclusiongraph.C
End_Macro

\anchor GrP3
Expand Down Expand Up @@ -527,11 +527,11 @@ is determined according to the number of objects having palette coloring in
the current pad.

Begin_Macro(source)
../../../tutorials/graphs/graphpalettecolor.C
../../../tutorials/graphs/gr104_palettecolor.C
End_Macro

Begin_Macro(source)
../../../tutorials/graphs/multigraphpalettecolor.C
../../../tutorials/graphs/gr105_multigraphpalettecolor.C
End_Macro

\anchor GrP6
Expand Down Expand Up @@ -630,18 +630,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/graphs/hlGraph*.C` files.
`$ROOTSYS/tutorials/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/graphs/gerrors2.C
root [0] .x $ROOTSYS/tutorials/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 dataframe/*.C dataframe/*.py)
# RDataFrame tutorial in graphs
list(APPEND dataframe_veto graphs/timeSeriesFromCSV_TDF.C)
list(APPEND dataframe_veto graphs/gr109_timeSeriesFromCSV_TDF.C)
# TMVA tutorials dependent on RDataFrame
list(APPEND dataframe_veto tmva/tmva*.C)
list(APPEND dataframe_veto tmva/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 graphs/graphstruct.C)
set(gviz_veto graphs/gr016_struct.C)
endif()

if(NOT TBB_FOUND AND NOT builtin_tbb)
Expand Down Expand Up @@ -434,7 +434,7 @@ if(MSVC AND NOT llvm13_broken_tests)
list(APPEND extra_veto
dataframe/df007_snapshot.C
graphics/earth.C
graphs/motorcycle.C
graphs/gr015_smooth.C
v7/ntuple/ntpl001_staff.C)
endif()
endif()
Expand Down Expand Up @@ -504,8 +504,8 @@ set(returncode_1 fit/fit2a.C
graphics/earth.C
graphics/pavetext.C
graphics/tmathtext.C graphics/tmathtext2.C
graphs/exclusiongraph.C
graphs/graphstruct.C
graphs/gr106_exclusiongraph.C
graphs/gr016_struct.C
hist/ContourList.C
hist/hbars.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 fit/fit1.C", "A Simple Fitting Example");
bar->AddButton("multifit", ".x fit/multifit.C", "Fitting in Subranges of Histograms");
bar->AddButton("h1ReadAndDraw", ".x hist/h1ReadAndDraw.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_basic.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("geometry", ".x geom/rootgeom.C", "Example of TGeoManager drawing");
bar->AddButton("file", ".x io/file.C", "The ROOT File Format");
Expand Down
20 changes: 20 additions & 0 deletions tutorials/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
40 changes: 0 additions & 40 deletions tutorials/graphs/gmultierrors.C

This file was deleted.

77 changes: 77 additions & 0 deletions tutorials/graphs/gr001_basic.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/// \file
/// \ingroup tutorial_graphs
/// \notebook
///
/// This tutorial demonstrates how to create simple graphs in ROOT. The example is divided into two sections:
/// - The first section plots data generated from arrays.
/// - The second section plots data read from a text file.
///
/// \macro_image
/// \macro_code
///
/// \author Rene Brun

#include<fstream> //Include the library for reading the data file

void gr001_basic() {
TCanvas *c1 = new TCanvas("c1","Two simple graphs",200,10,700,500);

c1->Divide(2,1); //Dividing the canvas in subpads for distinguishing the two examples, [See documentation](https://root.cern/doc/master/classTCanvas.html)

//FIRST EXAMPLE (Available data)
c1->cd(1);

const Int_t n = 20; //Fill the arrays x and y with the data points
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i*0.1;
y[i] = 10*sin(x[i]+0.2);
printf(" i %i %f %f \n",i,x[i],y[i]);
}

TGraph *gr1 = new TGraph(n,x,y); //Create a TGraph object, storing the number of data n and the x, y variables

//Set the color, width and style for the markers and line
gr1->SetLineColor(2);
gr1->SetLineWidth(4);
gr1->SetMarkerColor(4);
gr1->SetMarkerStyle(21);
gr1->SetTitle("Graph from available data"); //Choose title for the graph
gr1->GetXaxis()->SetTitle("X title"); //Choose title for the axis
gr1->GetYaxis()->SetTitle("Y title");

//Uncomment the following line to set a custom range for the x-axis (respectivly for the y-axis):
//gr1->GetXaxis()->SetRangeUser(0, 1.8);

gr1->Draw("ACP"); //"A" draw axes, "C" = draw a smooth line through the markers (optional) and "P" = draw markers for data points
//Optional customization can be done on a ROOT interactive session


//SECOND EXAMPLE (Data stored in a text file)
c1->cd(2);

const Int_t m = 20; //Known number of data points in the file
Double_t w[m], z[m];

std::ifstream file("data_basic.txt"); // Open the data file

// Use a for loop to read the data
for (Int_t i = 0; i < m; i++) {
file >> w[i] >> z[i]; //Fill the arrays with the data from the file
}
file.close(); //Close the file after reading


TGraph *gr2 = new TGraph(m, w, z); //Create a TGraph object for the file data
gr2->SetLineColor(4);
gr2->SetLineWidth(2);
gr2->SetMarkerColor(2);
gr2->SetMarkerStyle(20);
gr2->SetTitle("Graph from data file");
gr2->GetXaxis()->SetTitle("W title");
gr2->GetYaxis()->SetTitle("Z title");


gr2->Draw("ACP");
}

14 changes: 11 additions & 3 deletions tutorials/graphs/gerrors.C → tutorials/graphs/gr002_err_1gr.C
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
/// \file
/// \ingroup tutorial_graphs
/// \notebook -js
/// Draw a graph with error bars
/// 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 gerrors() {
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();
Expand Down
Loading