From 7793a83366edd35eaf70ec14c883fa1308cd773f Mon Sep 17 00:00:00 2001 From: dastudillo Date: Wed, 27 Nov 2024 16:34:42 +0100 Subject: [PATCH] [tutorials] Rename and comment and modernise graphs tutorials. Co-authored-by: Daniel P. Astudillo Co-authored-by: Emanuele Chiamulera --- documentation/users-guide/Graphs.md | 4 +- graf2d/gpad/src/TButton.cxx | 4 +- graf2d/gpad/src/TControlBar.cxx | 2 +- graf2d/gviz/doc/index.md | 2 +- graf2d/gviz/src/TGraphStruct.cxx | 2 +- hist/hist/src/TGraphSmooth.cxx | 2 +- hist/hist/src/TGraphTime.cxx | 2 +- hist/hist/src/TMultiGraph.cxx | 4 +- hist/hist/src/TScatter.cxx | 2 +- hist/histpainter/doc/index.md | 4 +- hist/histpainter/src/TGraphPainter.cxx | 12 +- test/stressGUI.cxx | 4 +- tutorials/CMakeLists.txt | 10 +- tutorials/demos.C | 4 +- tutorials/legacy/benchmarks.C | 12 +- tutorials/visualisation/graphs/data_basic.txt | 20 +++ .../graphs/{graph.C => gr001_basic.C} | 0 .../visualisation/graphs/gr002_err_1gr.C | 37 ++++ .../visualisation/graphs/gr003_err_2gr.C | 53 ++++++ .../visualisation/graphs/gr004_err_asym.C | 31 ++++ tutorials/visualisation/graphs/gr005_apply.C | 35 ++++ .../graphs/{scatter.C => gr006_scatter.C} | 17 +- .../visualisation/graphs/gr007_multigraph.C | 73 ++++++++ .../{gmultierrors.C => gr008_multierrors.C} | 21 ++- .../visualisation/graphs/gr009_bent_err.C | 33 ++++ .../graphs/{bent.py => gr009_bent_err.py} | 8 +- .../graphs/gr010_approx_smooth.C | 90 ++++++++++ ...graph2derrorsfit.C => gr011_2Derrorsfit.C} | 23 ++- tutorials/visualisation/graphs/gr012_polar.C | 98 +++++++++++ tutorials/visualisation/graphs/gr013_polar2.C | 49 ++++++ .../graphs/{graphpolar3.C => gr014_polar3.C} | 9 +- tutorials/visualisation/graphs/gr015_smooth.C | 103 +++++++++++ tutorials/visualisation/graphs/gr016_struct.C | 68 ++++++++ .../graphs/{gtime.C => gr017_time.C} | 16 +- .../graphs/{gtime2.C => gr018_time2.C} | 9 +- .../visualisation/graphs/gr101_shade_area.C | 43 +++++ .../visualisation/graphs/gr102_reverse_axis.C | 32 ++++ tutorials/visualisation/graphs/gr103_zones.C | 58 +++++++ .../graphs/{zones.py => gr103_zones.py} | 15 +- ...aphpalettecolor.C => gr104_palettecolor.C} | 8 +- ...color.C => gr105_multigraphpalettecolor.C} | 5 +- ...xclusiongraph.C => gr106_exclusiongraph.C} | 18 +- .../graphs/gr107_exclusiongraph2.C | 162 ++++++++++++++++++ ...iesFromCSV.C => gr108_timeSeriesFromCSV.C} | 8 +- ...sFromCSV.py => gr108_timeSeriesFromCSV.py} | 4 +- ...SV_TDF.C => gr109_timeSeriesFromCSV_TDF.C} | 8 +- .../visualisation/graphs/gr110_logscale.C | 43 +++++ tutorials/visualisation/graphs/gr111_legend.C | 42 +++++ ...raphreverse.C => gr112_err_reverse_axis.C} | 48 +++--- .../graphs/{waves.C => gr201_waves.C} | 57 +++++- .../{graphtext.C => gr202_textmarkers.C} | 13 +- .../graphs/{hlGraph1.C => gr301_highlight1.C} | 5 +- .../graphs/{hlGraph2.C => gr302_highlight2.C} | 5 +- .../graphs/{zdemo.C => gr303_zdemo.C} | 2 +- tutorials/visualisation/graphs/graphApply.C | 56 ------ tutorials/visualisation/graphs/graphpolar2.C | 36 ---- tutorials/visualisation/graphs/index.md | 111 ++++++++++++ tutorials/visualisation/graphs/zones.C | 39 ----- tutorials/visualisation/image/trans_graph.C | 4 +- 59 files changed, 1434 insertions(+), 251 deletions(-) create mode 100644 tutorials/visualisation/graphs/data_basic.txt rename tutorials/visualisation/graphs/{graph.C => gr001_basic.C} (100%) create mode 100644 tutorials/visualisation/graphs/gr002_err_1gr.C create mode 100644 tutorials/visualisation/graphs/gr003_err_2gr.C create mode 100644 tutorials/visualisation/graphs/gr004_err_asym.C create mode 100644 tutorials/visualisation/graphs/gr005_apply.C rename tutorials/visualisation/graphs/{scatter.C => gr006_scatter.C} (59%) create mode 100644 tutorials/visualisation/graphs/gr007_multigraph.C rename tutorials/visualisation/graphs/{gmultierrors.C => gr008_multierrors.C} (56%) create mode 100644 tutorials/visualisation/graphs/gr009_bent_err.C rename tutorials/visualisation/graphs/{bent.py => gr009_bent_err.py} (77%) create mode 100644 tutorials/visualisation/graphs/gr010_approx_smooth.C rename tutorials/visualisation/graphs/{graph2derrorsfit.C => gr011_2Derrorsfit.C} (52%) create mode 100644 tutorials/visualisation/graphs/gr012_polar.C create mode 100644 tutorials/visualisation/graphs/gr013_polar2.C rename tutorials/visualisation/graphs/{graphpolar3.C => gr014_polar3.C} (65%) create mode 100644 tutorials/visualisation/graphs/gr015_smooth.C create mode 100644 tutorials/visualisation/graphs/gr016_struct.C rename tutorials/visualisation/graphs/{gtime.C => gr017_time.C} (75%) rename tutorials/visualisation/graphs/{gtime2.C => gr018_time2.C} (89%) create mode 100644 tutorials/visualisation/graphs/gr101_shade_area.C create mode 100644 tutorials/visualisation/graphs/gr102_reverse_axis.C create mode 100644 tutorials/visualisation/graphs/gr103_zones.C rename tutorials/visualisation/graphs/{zones.py => gr103_zones.py} (50%) rename tutorials/visualisation/graphs/{graphpalettecolor.C => gr104_palettecolor.C} (83%) rename tutorials/visualisation/graphs/{multigraphpalettecolor.C => gr105_multigraphpalettecolor.C} (92%) rename tutorials/visualisation/graphs/{exclusiongraph.C => gr106_exclusiongraph.C} (56%) create mode 100644 tutorials/visualisation/graphs/gr107_exclusiongraph2.C rename tutorials/visualisation/graphs/{timeSeriesFromCSV.C => gr108_timeSeriesFromCSV.C} (87%) rename tutorials/visualisation/graphs/{timeSeriesFromCSV.py => gr108_timeSeriesFromCSV.py} (90%) rename tutorials/visualisation/graphs/{timeSeriesFromCSV_TDF.C => gr109_timeSeriesFromCSV_TDF.C} (81%) create mode 100644 tutorials/visualisation/graphs/gr110_logscale.C create mode 100644 tutorials/visualisation/graphs/gr111_legend.C rename tutorials/visualisation/graphs/{graphreverse.C => gr112_err_reverse_axis.C} (58%) rename tutorials/visualisation/graphs/{waves.C => gr201_waves.C} (59%) rename tutorials/visualisation/graphs/{graphtext.C => gr202_textmarkers.C} (68%) rename tutorials/visualisation/graphs/{hlGraph1.C => gr301_highlight1.C} (89%) rename tutorials/visualisation/graphs/{hlGraph2.C => gr302_highlight2.C} (94%) rename tutorials/visualisation/graphs/{zdemo.C => gr303_zdemo.C} (99%) delete mode 100644 tutorials/visualisation/graphs/graphApply.C delete mode 100644 tutorials/visualisation/graphs/graphpolar2.C create mode 100644 tutorials/visualisation/graphs/index.md delete mode 100644 tutorials/visualisation/graphs/zones.C diff --git a/documentation/users-guide/Graphs.md b/documentation/users-guide/Graphs.md index 0476a1180caa7..035a83566358c 100644 --- a/documentation/users-guide/Graphs.md +++ b/documentation/users-guide/Graphs.md @@ -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} { @@ -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) diff --git a/graf2d/gpad/src/TButton.cxx b/graf2d/gpad/src/TButton.cxx index 3abba070c5c71..a29ba88578b2f 100644 --- a/graf2d/gpad/src/TButton.cxx +++ b/graf2d/gpad/src/TButton.cxx @@ -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); diff --git a/graf2d/gpad/src/TControlBar.cxx b/graf2d/gpad/src/TControlBar.cxx index c94f52df6058a..7bfa531f63db0 100644 --- a/graf2d/gpad/src/TControlBar.cxx +++ b/graf2d/gpad/src/TControlBar.cxx @@ -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"); diff --git a/graf2d/gviz/doc/index.md b/graf2d/gviz/doc/index.md index 2e7f22a3621ce..2a0ce4298ba36 100644 --- a/graf2d/gviz/doc/index.md +++ b/graf2d/gviz/doc/index.md @@ -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. diff --git a/graf2d/gviz/src/TGraphStruct.cxx b/graf2d/gviz/src/TGraphStruct.cxx index ab4de0041e5f4..6d24ec29e6dee 100644 --- a/graf2d/gviz/src/TGraphStruct.cxx +++ b/graf2d/gviz/src/TGraphStruct.cxx @@ -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. diff --git a/hist/hist/src/TGraphSmooth.cxx b/hist/hist/src/TGraphSmooth.cxx index 82ab4fe1be8db..951067768f0d9 100644 --- a/hist/hist/src/TGraphSmooth.cxx +++ b/hist/hist/src/TGraphSmooth.cxx @@ -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() diff --git a/hist/hist/src/TGraphTime.cxx b/hist/hist/src/TGraphTime.cxx index 67f42450d57ec..0fbaf074e6b68 100644 --- a/hist/hist/src/TGraphTime.cxx +++ b/hist/hist/src/TGraphTime.cxx @@ -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 */ //////////////////////////////////////////////////////////////////////////////// diff --git a/hist/hist/src/TMultiGraph.cxx b/hist/hist/src/TMultiGraph.cxx index f4b01a074b023..dd8dd2b6a98c3 100644 --- a/hist/hist/src/TMultiGraph.cxx +++ b/hist/hist/src/TMultiGraph.cxx @@ -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 @@ -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 diff --git a/hist/hist/src/TScatter.cxx b/hist/hist/src/TScatter.cxx index 3134326c9b2db..9250576f8ddaa 100644 --- a/hist/hist/src/TScatter.cxx +++ b/hist/hist/src/TScatter.cxx @@ -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 diff --git a/hist/histpainter/doc/index.md b/hist/histpainter/doc/index.md index f31c0679ec5fc..ec2c4e0677466 100644 --- a/hist/histpainter/doc/index.md +++ b/hist/histpainter/doc/index.md @@ -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. diff --git a/hist/histpainter/src/TGraphPainter.cxx b/hist/histpainter/src/TGraphPainter.cxx index 0f4b986799096..1abfc67733532 100644 --- a/hist/histpainter/src/TGraphPainter.cxx +++ b/hist/histpainter/src/TGraphPainter.cxx @@ -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 @@ -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 @@ -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 highlight mode and user function diff --git a/test/stressGUI.cxx b/test/stressGUI.cxx index b8b16217574df..5d466e1142416 100644 --- a/test/stressGUI.cxx +++ b/test/stressGUI.cxx @@ -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"); diff --git a/tutorials/CMakeLists.txt b/tutorials/CMakeLists.txt index 054b30cbd0cda..238a492b3e386 100644 --- a/tutorials/CMakeLists.txt +++ b/tutorials/CMakeLists.txt @@ -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) @@ -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) @@ -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() @@ -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 diff --git a/tutorials/demos.C b/tutorials/demos.C index 730d903593ed7..ab1ff1ffe8e81 100644 --- a/tutorials/demos.C +++ b/tutorials/demos.C @@ -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"); diff --git a/tutorials/legacy/benchmarks.C b/tutorials/legacy/benchmarks.C index acccf7ec24dd0..6c10e2f857918 100644 --- a/tutorials/legacy/benchmarks.C +++ b/tutorials/legacy/benchmarks.C @@ -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"); @@ -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"); diff --git a/tutorials/visualisation/graphs/data_basic.txt b/tutorials/visualisation/graphs/data_basic.txt new file mode 100644 index 0000000000000..210b67d98d104 --- /dev/null +++ b/tutorials/visualisation/graphs/data_basic.txt @@ -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 \ No newline at end of file diff --git a/tutorials/visualisation/graphs/graph.C b/tutorials/visualisation/graphs/gr001_basic.C similarity index 100% rename from tutorials/visualisation/graphs/graph.C rename to tutorials/visualisation/graphs/gr001_basic.C diff --git a/tutorials/visualisation/graphs/gr002_err_1gr.C b/tutorials/visualisation/graphs/gr002_err_1gr.C new file mode 100644 index 0000000000000..9dfb0bcb7795c --- /dev/null +++ b/tutorials/visualisation/graphs/gr002_err_1gr.C @@ -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(); +} diff --git a/tutorials/visualisation/graphs/gr003_err_2gr.C b/tutorials/visualisation/graphs/gr003_err_2gr.C new file mode 100644 index 0000000000000..a560cc080f431 --- /dev/null +++ b/tutorials/visualisation/graphs/gr003_err_2gr.C @@ -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"); +} diff --git a/tutorials/visualisation/graphs/gr004_err_asym.C b/tutorials/visualisation/graphs/gr004_err_asym.C new file mode 100644 index 0000000000000..a02fa6caf257f --- /dev/null +++ b/tutorials/visualisation/graphs/gr004_err_asym.C @@ -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 +} diff --git a/tutorials/visualisation/graphs/gr005_apply.C b/tutorials/visualisation/graphs/gr005_apply.C new file mode 100644 index 0000000000000..8c8b6509c255b --- /dev/null +++ b/tutorials/visualisation/graphs/gr005_apply.C @@ -0,0 +1,35 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// A macro to demonstrate the functionality of TGraph::Apply() method. +/// TGraph::Apply applies a function `f` to all the data TGraph points, `f` may be a 1-D function TF1 or 2-d function TF2. +/// The Y values of the graph are replaced by the new values computed using the function. +/// +/// +/// The Apply() method can be used as well for TGraphErrors and TGraphAsymmErrors. +/// +/// \macro_image +/// \macro_code +/// +/// \author Miro Helbich + +void gr005_apply() { + + const Int_t npoints=3; + Double_t xaxis[npoints] = {1.,2.,3.}; + Double_t yaxis[npoints] = {10.,20.,30.}; + + TGraph *gr1 = new TGraph(npoints,xaxis,yaxis); + TF2 *ff = new TF2("ff","-1./y"); //Defining the function `f` + + TCanvas *c1 = new TCanvas("c1","c1", 0,0,700,500); + c1->Divide(2,1); + + c1->cd(1); + gr1->DrawClone("A*"); //Using DrawClone to create a copy of the graph in the canvas. + c1->cd(2); + gr1->Apply(ff); //Applies the function `f` to all the data TGraph points + gr1->Draw("A*"); + /* Without DrawClone, the modifications to gr1 via Apply(ff) are reflected in the original graph + displayed in c1 (the two drawn graphs are not independent). */ +} diff --git a/tutorials/visualisation/graphs/scatter.C b/tutorials/visualisation/graphs/gr006_scatter.C similarity index 59% rename from tutorials/visualisation/graphs/scatter.C rename to tutorials/visualisation/graphs/gr006_scatter.C index 4c111a0c0ef67..6c2b4b00d7f55 100644 --- a/tutorials/visualisation/graphs/scatter.C +++ b/tutorials/visualisation/graphs/gr006_scatter.C @@ -1,14 +1,15 @@ /// \file /// \ingroup tutorial_graphs /// \notebook -/// Draw a scatter plot. +/// Draw a scatter plot for 4 variables, mapped to: x, y, marker colour and marker size. +/// +/// TScatter is available since ROOT v.6.30. See the [TScatter documentation](https://root.cern/doc/master/classTScatter.html) /// /// \macro_image /// \macro_code -/// /// \author Olivier Couet -void scatter() +void gr006_scatter() { auto canvas = new TCanvas(); canvas->SetRightMargin(0.14); @@ -20,6 +21,7 @@ void scatter() double c[n]; double s[n]; +<<<<<<<< HEAD:tutorials/visualisation/graphs/scatter.C // Define four random data set auto r = new TRandom(); for (int i = 0; i < n; i++) { @@ -27,6 +29,15 @@ void scatter() y[i] = 200 * r->Rndm(i); c[i] = 300 * r->Rndm(i); s[i] = 400 * r->Rndm(i); +======== + // Define four random data sets + auto r = new TRandom(); + for (int i=0; iRndm(i); + y[i] = 200*r->Rndm(i); + c[i] = 300*r->Rndm(i); + s[i] = 400*r->Rndm(i); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr006_scatter.C } auto scatter = new TScatter(n, x, y, c, s); diff --git a/tutorials/visualisation/graphs/gr007_multigraph.C b/tutorials/visualisation/graphs/gr007_multigraph.C new file mode 100644 index 0000000000000..a313817109f60 --- /dev/null +++ b/tutorials/visualisation/graphs/gr007_multigraph.C @@ -0,0 +1,73 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// TMultiGraph is used to combine multiple graphs into one plot. +/// Allowing to overlay different graphs can be useful for comparing different datasets +/// or for plotting multiple related graphs on the same canvas. +/// +/// \macro_image +/// \macro_code +/// +/// \author Rene Brun + + +void gr007_multigraph() { + gStyle->SetOptFit(); + auto c1 = new TCanvas("c1","multigraph",700,500); + c1->SetGrid(); + + //Initialize a TMultiGraph to hold multiple graphs + //This ensures the entire dataset from all added graphs is visible without manual range adjustments. + auto mg = new TMultiGraph(); + + //Create first graph + const Int_t n1 = 10; + Double_t px1[] = {-0.1, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95}; + Double_t py1[] = {-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}; + auto gr1 = new TGraphErrors(n1,px1,py1,ex1,ey1); + gr1->SetMarkerColor(kBlue); + gr1->SetMarkerStyle(21); + + gr1->Fit("gaus","q"); + auto func1 = (TF1 *) gr1->GetListOfFunctions()->FindObject("gaus"); + func1->SetLineColor(kBlue); + + //Add the first graph to the multigraph + mg->Add(gr1); + + //Create second graph + const Int_t n2 = 10; + Float_t x2[] = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01}; + Float_t y2[] = {2.1,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}; + auto gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2); + gr2->SetMarkerColor(kRed); + gr2->SetMarkerStyle(20); + + gr2->Fit("pol5","q"); + auto func2 = (TF1 *) gr2->GetListOfFunctions()->FindObject("pol5"); + func2->SetLineColor(kRed); + func2->SetLineStyle(2); + + //Add the second graph to the multigraph + mg->Add(gr2); + + mg->Draw("ap"); + + //Force drawing of canvas to generate the fit TPaveStats + c1->Update(); + + auto stats1 = (TPaveStats*) gr1->GetListOfFunctions()->FindObject("stats"); + auto stats2 = (TPaveStats*) gr2->GetListOfFunctions()->FindObject("stats"); + + if (stats1 && stats2) { + stats1->SetTextColor(kBlue); + stats2->SetTextColor(kRed); + stats1->SetX1NDC(0.12); stats1->SetX2NDC(0.32); stats1->SetY1NDC(0.82); + stats2->SetX1NDC(0.72); stats2->SetX2NDC(0.92); stats2->SetY1NDC(0.75); + c1->Modified(); + } +} diff --git a/tutorials/visualisation/graphs/gmultierrors.C b/tutorials/visualisation/graphs/gr008_multierrors.C similarity index 56% rename from tutorials/visualisation/graphs/gmultierrors.C rename to tutorials/visualisation/graphs/gr008_multierrors.C index fc3f30230b8e7..946107647c691 100644 --- a/tutorials/visualisation/graphs/gmultierrors.C +++ b/tutorials/visualisation/graphs/gr008_multierrors.C @@ -1,15 +1,15 @@ /// \file /// \ingroup tutorial_graphs /// \notebook -js -/// Draw a graph with multiple y errors +/// Draw a graph with multiple errors. Multi errors can be usefull for distinguishing different type of errors, +/// for example statistical and systematic errors. /// /// \macro_image /// \macro_code -/// +/// /// \author Simon Spies -void gmultierrors() -{ +void gr008_multierrors() { TCanvas *c1 = new TCanvas("c1", "A Simple Graph with multiple y-errors", 200, 10, 700, 500); c1->SetGrid(); c1->GetFrame()->SetBorderSize(12); @@ -29,14 +29,17 @@ void gmultierrors() gme->AddYError(np, eylsys, eyhsys); gme->SetMarkerStyle(20); gme->SetLineColor(kRed); - gme->GetAttLine(0)->SetLineColor(kRed); - gme->GetAttLine(1)->SetLineColor(kBlue); + gme->GetAttLine(0)->SetLineColor(kRed); //Color for statistical error bars + gme->GetAttLine(1)->SetLineColor(kBlue); //Color for systematic error bars gme->GetAttFill(1)->SetFillStyle(0); - // Graph and x erros drawn with "APS" - // Stat Errors drawn with "Z" - // Sys Errors drawn with "5 s=0.5" + //Graph is drawn with the option "APS": "A" draw axes, "P" draw points and "S" draw symmetric horizontal error bars (x-errors) + //Statistical y-errors are drawn with the option "Z" vertical error bars. + //Systematic y-errors are drawn with the option "5 s=0.5": + //"5" draw rectangles to represent the systematic y-error bars. + //"s=0.5" scale the rectangles horizontally (along the x-axis) by a factor of 0.5. gme->Draw("APS ; Z ; 5 s=0.5"); + c1->Update(); } diff --git a/tutorials/visualisation/graphs/gr009_bent_err.C b/tutorials/visualisation/graphs/gr009_bent_err.C new file mode 100644 index 0000000000000..5bfe00506786f --- /dev/null +++ b/tutorials/visualisation/graphs/gr009_bent_err.C @@ -0,0 +1,33 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook -js +/// Graph with bent error bars. See the [TGraphBentErrors documentation](https://root.cern/doc/master/classTGraphBentErrors.html) +/// +/// exl / exh: low and high (left/right) errors in x; similar for y +/// e*d: delta, in axis units, to be added/subtracted (if >0 or <0) in x or y from +/// the data point's position to use as end point of the corresponding error +/// +/// \macro_image +/// \macro_code +/// \author Olivier Couet + +void gr009_bent_err() +{ + const Int_t n = 10; + Double_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95}; + Double_t y[n] = {1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1}; + Double_t exl[n] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05}; + Double_t eyl[n] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8}; + Double_t exh[n] = {.02,.08,.05,.05,.03,.03,.04,.05,.06,.03}; + Double_t eyh[n] = {.6,.5,.4,.3,.2,.2,.3,.4,.5,.6}; + Double_t exld[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.0,.0}; + Double_t eyld[n] = {.0,.0,.05,.0,.0,.0,.0,.0,.0,.0}; + Double_t exhd[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.0,.0}; + Double_t eyhd[n] = {.0,.0,.0,.0,.0,.0,.0,.0,.05,.0}; + TGraphBentErrors *gr = new TGraphBentErrors( + n,x,y,exl,exh,eyl,eyh,exld,exhd,eyld,eyhd); + gr->SetTitle("TGraphBentErrors Example"); + gr->SetMarkerColor(4); + gr->SetMarkerStyle(21); + gr->Draw("ALP"); +} diff --git a/tutorials/visualisation/graphs/bent.py b/tutorials/visualisation/graphs/gr009_bent_err.py similarity index 77% rename from tutorials/visualisation/graphs/bent.py rename to tutorials/visualisation/graphs/gr009_bent_err.py index 63c10a23bfb7b..5ea74fe765e0f 100644 --- a/tutorials/visualisation/graphs/bent.py +++ b/tutorials/visualisation/graphs/gr009_bent_err.py @@ -1,7 +1,13 @@ ## \file ## \ingroup tutorial_graphs ## \notebook -js -## Bent error bars. Inspired from work of Olivier Couet. +## Graph with bent error bars. Inspired from work of Olivier Couet. +## +## See the [TGraphBentErrors documentation](https://root.cern/doc/master/classTGraphBentErrors.html) +## +## exl / exh: low and high (left/right) errors in x; similar for y +## e*d: delta, in axis units, to be added/subtracted (if >0 or <0) in x or y from +## the data point's position to use as end point of the corresponding error ## ## \macro_image ## \macro_code diff --git a/tutorials/visualisation/graphs/gr010_approx_smooth.C b/tutorials/visualisation/graphs/gr010_approx_smooth.C new file mode 100644 index 0000000000000..35f171460037d --- /dev/null +++ b/tutorials/visualisation/graphs/gr010_approx_smooth.C @@ -0,0 +1,90 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook -js +/// Create a TGraphSmooth and show the usage of the interpolation function Approx +/// +/// See the [TGraphSmooth documentation](https://root.cern/doc/master/classTGraphSmooth.html) +/// +/// \macro_image +/// \macro_code +/// \author Christian Stratowa, Vienna, Austria. + +TCanvas *vC1; +TGraph *grxy, *grin, *grout; + +void gr010_approx_smooth(Int_t pad, const char *title, const char *xt, const char *yt) +{ + vC1->cd(pad); + TH1F *vFrame = gPad->DrawFrame(0,0,15,150); + vFrame->SetTitle(title); + vFrame->SetTitleSize(0.2); + vFrame->SetXTitle(xt); + vFrame->SetYTitle(yt); + grxy->SetMarkerColor(kBlue); + grxy->SetMarkerStyle(21); + grxy->SetMarkerSize(0.5); + grxy->Draw("P"); + grin->SetMarkerColor(kRed); + grin->SetMarkerStyle(5); + grin->SetMarkerSize(0.7); + grin->Draw("P"); + grout->DrawClone("LP"); +} + +void gr10_approx_smooth() +{ +// Test data (square) + Int_t n = 11; + Double_t x[] = {1,2,3,4,5,6,6,6,8,9,10}; + Double_t y[] = {1,4,9,16,25,25,36,49,64,81,100}; + grxy = new TGraph(n,x,y); + +// X values, for which y values should be interpolated + Int_t nout = 14; + Double_t xout[] = + {1.2,1.7,2.5,3.2,4.4,5.2,5.7,6.5,7.6,8.3,9.7,10.4,11.3,13}; + +// Create Canvas + vC1 = new TCanvas("vC1","square",200,10,700,700); + vC1->Divide(2,2); + +// Initialize graph with data + grin = new TGraph(n,x,y); +// Interpolate at equidistant points (use mean for tied x-values) + TGraphSmooth *gs = new TGraphSmooth("normal"); + grout = gs->Approx(grin,"linear"); + DrawSmooth(1,"Approx: ties = mean","X-axis","Y-axis"); + +// Re-initialize graph with data +// (since graph points were set to unique vales) + grin = new TGraph(n,x,y); +// Interpolate at given points xout + grout = gs->Approx(grin,"linear", 14, xout, 0, 130); + DrawSmooth(2,"Approx: ties = mean","",""); + +// Print output variables for given values xout + Int_t vNout = grout->GetN(); + Double_t vXout, vYout; + for (Int_t k=0;kGetPoint(k, vXout, vYout); + cout << "k= " << k << " vXout[k]= " << vXout + << " vYout[k]= " << vYout << endl; + } + +// Re-initialize graph with data + grin = new TGraph(n,x,y); +// Interpolate at equidistant points (use min for tied x-values) +// _grout = gs->Approx(grin,"linear", 50, 0, 0, 0, 1, 0, "min");_ + grout = gs->Approx(grin,"constant", 50, 0, 0, 0, 1, 0.5, "min"); + DrawSmooth(3,"Approx: ties = min","",""); + +// Re-initialize graph with data + grin = new TGraph(n,x,y); +// Interpolate at equidistant points (use max for tied x-values) + grout = gs->Approx(grin,"linear", 14, xout, 0, 0, 2, 0, "max"); + DrawSmooth(4,"Approx: ties = max","",""); + +// Cleanup + delete gs; +} + diff --git a/tutorials/visualisation/graphs/graph2derrorsfit.C b/tutorials/visualisation/graphs/gr011_2Derrorsfit.C similarity index 52% rename from tutorials/visualisation/graphs/graph2derrorsfit.C rename to tutorials/visualisation/graphs/gr011_2Derrorsfit.C index f5c8593a5b4e3..732ffe9aa7e8c 100644 --- a/tutorials/visualisation/graphs/graph2derrorsfit.C +++ b/tutorials/visualisation/graphs/gr011_2Derrorsfit.C @@ -1,11 +1,10 @@ /// \file /// \ingroup tutorial_graphs /// \notebook -/// Draw and fit a TGraph2DErrors +/// Create, draw and fit a TGraph2DErrors. See the [TGraph2DErrors documentation](https://root.cern/doc/master/classTGraph2DErrors.html) /// /// \macro_image /// \macro_code -/// /// \author Olivier Couet #include @@ -15,7 +14,7 @@ #include #include -void graph2derrorsfit() +void gr011_2Derrorsfit() { TCanvas *c1 = new TCanvas("c1"); @@ -23,12 +22,21 @@ void graph2derrorsfit() Double_t e = 0.3; Int_t nd = 500; + // To generate some random data to put into the graph TRandom r; +<<<<<<<< HEAD:tutorials/visualisation/graphs/graph2derrorsfit.C TF2 *f2 = new TF2("f2", "1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200", -6, 6, -6, 6); f2->SetParameters(1, 1); +======== + TF2 *f2 = new TF2("f2","1000*(([0]*sin(x)/x)*([1]*sin(y)/y))+200",-6,6,-6,6); + f2->SetParameters(1,1); + +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr011_2Derrorsfit.C TGraph2DErrors *dte = new TGraph2DErrors(nd); - // Fill the 2D graph + // Fill the 2D graph. It was created only specifying the number of points, so all + // elements are empty. We now "fill" the values and errors with SetPoint and SetPointError. + // Note that the first point has index zero Double_t zmax = 0; for (Int_t i = 0; i < nd; i++) { f2->GetRandom2(x, y); @@ -42,8 +50,15 @@ void graph2derrorsfit() ez = TMath::Abs(z * rnd); dte->SetPointError(i, ex, ey, ez); } + // If the fit is not needed, just draw dte here and skip the lines below + // dte->Draw("A p0"); +<<<<<<<< HEAD:tutorials/visualisation/graphs/graph2derrorsfit.C f2->SetParameters(0.5, 1.5); +======== + // To do the fit we use a function, in this example the same f2 from above + f2->SetParameters(0.5,1.5); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr011_2Derrorsfit.C dte->Fit(f2); TF2 *fit2 = (TF2 *)dte->FindObject("f2"); fit2->SetTitle("Minuit fit result on the Graph2DErrors points"); diff --git a/tutorials/visualisation/graphs/gr012_polar.C b/tutorials/visualisation/graphs/gr012_polar.C new file mode 100644 index 0000000000000..dae8ee6c0cf59 --- /dev/null +++ b/tutorials/visualisation/graphs/gr012_polar.C @@ -0,0 +1,98 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// Create and draw a polar graph. See the [TGraphPolar documentation](https://root.cern/doc/master/classTGraphPolar.html) +/// +/// Since TGraphPolar is a TGraphErrors, it is painted with +/// [TGraphPainter](https://root.cern/doc/master/classTGraphPainter.html) options. +/// +/// With GetPolargram we retrieve the polar axis to format it; see the +/// [TGraphPolargram documentation](https://root.cern/doc/master/classTGraphPolargram.html) +/// +/// \macro_image +/// \macro_code +/// \author Olivier Couet + +void gr012_polar() +{ + // Illustrates how to use TGraphPolar + + TCanvas * CPol = new TCanvas("CPol","TGraphPolar Examples",1200,600); + CPol->Divide(2,1); + + // Left-side pad. Two graphs without errors + CPol->cd(1); + Double_t xmin=0; + Double_t xmax=TMath::Pi()*2; + + Double_t x[1000]; + Double_t y[1000]; + Double_t xval1[20]; + Double_t yval1[20]; + + // Graph 1 to be drawn with line and fill + TF1 * fplot = new TF1("fplot","cos(2*x)*cos(20*x)",xmin,xmax); + for (Int_t ipt = 0; ipt < 1000; ipt++){ + x[ipt] = ipt*(xmax-xmin)/1000 + xmin; + y[ipt] = fplot->Eval(x[ipt]); + } + TGraphPolar * grP = new TGraphPolar(1000,x,y); + grP->SetLineColor(2); + grP->SetLineWidth(2); + grP->SetFillStyle(3012); + grP->SetFillColor(2); + grP->Draw("AFL"); + + // Graph 2 to be drawn superposed over graph 1, with curve and polymarker + for (Int_t ipt = 0; ipt < 20; ipt++){ + xval1[ipt] = x[1000/20*ipt]; + yval1[ipt] = y[1000/20*ipt]; + } + TGraphPolar * grP1 = new TGraphPolar(20,xval1,yval1); + grP1->SetMarkerStyle(29); + grP1->SetMarkerSize(2); + grP1->SetMarkerColor(4); + grP1->SetLineColor(4); + grP1->Draw("CP"); + + // To format the polar axis, we retrieve the TGraphPolargram. + // First update the canvas, otherwise GetPolargram returns 0 + CPol->Update(); + if (grP1->GetPolargram()) { + grP1->GetPolargram()->SetTextColor(8); + grP1->GetPolargram()->SetRangePolar(-TMath::Pi(),TMath::Pi()); + grP1->GetPolargram()->SetNdivPolar(703); + grP1->GetPolargram()->SetToRadian(); // tell ROOT that the x and xval1 are in radians + } + + // Right-side pad. One graph with errors + CPol->cd(2); + Double_t x2[30]; + Double_t y2[30]; + Double_t ex[30]; + Double_t ey[30]; + for (Int_t ipt = 0; ipt < 30; ipt++){ + x2[ipt] = x[1000/30*ipt]; + y2[ipt] = 1.2 + 0.4*sin(TMath::Pi()*2*ipt/30); + ex[ipt] = 0.2+0.1*cos(2*TMath::Pi()/30*ipt); + ey[ipt] = 0.2; + } + + // Grah to be drawn with polymarker and errors + TGraphPolar * grPE = new TGraphPolar(30,x2,y2,ex,ey); + grPE->SetMarkerStyle(22); + grPE->SetMarkerSize(1.5); + grPE->SetMarkerColor(5); + grPE->SetLineColor(6); + grPE->SetLineWidth(2); + grPE->Draw("EP"); + + // To format the polar axis, we retrieve the TGraphPolargram. + // First update the canvas, otherwise GetPolargram returns 0 + CPol->Update(); + if (grPE->GetPolargram()) { + grPE->GetPolargram()->SetTextSize(0.03); + grPE->GetPolargram()->SetTwoPi(); + grPE->GetPolargram()->SetToRadian(); // tell ROOT that the x2 values are in radians + } +} diff --git a/tutorials/visualisation/graphs/gr013_polar2.C b/tutorials/visualisation/graphs/gr013_polar2.C new file mode 100644 index 0000000000000..86d943c55f82b --- /dev/null +++ b/tutorials/visualisation/graphs/gr013_polar2.C @@ -0,0 +1,49 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// Create and draw a polar graph with errors and polar axis in radians (PI fractions). +/// See the [TGraphPolar documentation](https://root.cern/doc/master/classTGraphPolar.html) +/// +/// Since TGraphPolar is a TGraphErrors, it is painted with +/// [TGraphPainter](https://root.cern/doc/master/classTGraphPainter.html) options. +/// +/// With GetPolargram we retrieve the polar axis to format it; see the +/// [TGraphPolargram documentation](https://root.cern/doc/master/classTGraphPolargram.html) +/// +/// \macro_image +/// \macro_code +/// \author Olivier Couet + +void gr013_polar2() +{ + TCanvas * CPol = new TCanvas("CPol","TGraphPolar Example",500,500); + + Double_t theta[8]; + Double_t radius[8]; + Double_t etheta[8]; + Double_t eradius[8]; + + for (int i=0; i<8; i++) { + theta[i] = (i+1)*(TMath::Pi()/4.); + radius[i] = (i+1)*0.05; + etheta[i] = TMath::Pi()/8.; + eradius[i] = 0.05; + } + + TGraphPolar * grP1 = new TGraphPolar(8, theta, radius, etheta, eradius); + grP1->SetTitle(""); + + grP1->SetMarkerStyle(20); + grP1->SetMarkerSize(2.); + grP1->SetMarkerColor(4); + grP1->SetLineColor(2); + grP1->SetLineWidth(3); + // Draw with polymarker and errors + grP1->Draw("PE"); + + // To format the polar axis, we retrieve the TGraphPolargram. + // First update the canvas, otherwise GetPolargram returns 0 + CPol->Update(); + if (grP1->GetPolargram()) + grP1->GetPolargram()->SetToRadian(); // tell ROOT that the theta values are in radians +} diff --git a/tutorials/visualisation/graphs/graphpolar3.C b/tutorials/visualisation/graphs/gr014_polar3.C similarity index 65% rename from tutorials/visualisation/graphs/graphpolar3.C rename to tutorials/visualisation/graphs/gr014_polar3.C index 34102ffededb9..515960415be93 100644 --- a/tutorials/visualisation/graphs/graphpolar3.C +++ b/tutorials/visualisation/graphs/gr014_polar3.C @@ -1,14 +1,17 @@ /// \file /// \ingroup tutorial_graphs /// \notebook -/// Create and draw a polar graph with PI axis using a TF1. +/// Create a polar graph using a TF1 and draw it with PI axis. +/// See the [TGraphPolar documentation](https://root.cern/doc/master/classTGraphPolar.html) +/// +/// Since TGraphPolar is a TGraphErrors, it is painted with +/// [TGraphPainter](https://root.cern/doc/master/classTGraphPainter.html) options. /// /// \macro_image /// \macro_code -/// /// \author Olivier Couet -void graphpolar3() +void gr014_polar3() { TCanvas *CPol = new TCanvas("CPol", "TGraphPolar Examples", 500, 500); diff --git a/tutorials/visualisation/graphs/gr015_smooth.C b/tutorials/visualisation/graphs/gr015_smooth.C new file mode 100644 index 0000000000000..d4c7f2160f3ba --- /dev/null +++ b/tutorials/visualisation/graphs/gr015_smooth.C @@ -0,0 +1,103 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// Show scatter plot smoothers: ksmooth, lowess, supsmu, +/// as described in: +/// +/// Modern Applied Statistics with S-Plus, 3rd Edition +/// W.N. Venables and B.D. Ripley +/// Chapter 9: Smooth Regression, Figure 9.1 +/// +/// Example is a set of data on 133 observations of acceleration against time +/// for a simulated motorcycle accident, taken from Silverman (1985). The data +/// are read from motorcycle.dat (2 columns of floats) +/// +/// \macro_image +/// \macro_code +/// \author Christian Stratowa, Vienna, Austria + +#include "TString.h" +#include "TInterpreter.h" +#include +#include "TH1.h" +#include "TGraphSmooth.h" +#include "TCanvas.h" +#include "TSystem.h" + + +TCanvas *vC1; +TGraph *grin, *grout; + +void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt) +{ + vC1->cd(pad); + TH1F *vFrame = gPad->DrawFrame(0,-130,60,70); + vFrame->SetTitle(title); + vFrame->SetTitleSize(0.2); + vFrame->SetXTitle(xt); + vFrame->SetYTitle(yt); + grin->Draw("P"); + grout->DrawClone("LPX"); +} + +void gr015_smooth() +{ +// data taken from R library MASS: mcycle.txt + TString dir = gROOT->GetTutorialDir(); + dir.Append("/graphs/"); + dir.ReplaceAll("/./","/"); + +// read file and add to fit object + Double_t *x = new Double_t[133]; + Double_t *y = new Double_t[133]; + Double_t vX, vY; + Int_t vNData = 0; + ifstream vInput; + vInput.open(Form("%smotorcycle.dat",dir.Data())); + while (1) { + vInput >> vX >> vY; + if (!vInput.good()) break; + x[vNData] = vX; + y[vNData] = vY; + vNData++; + }//while + vInput.close(); + grin = new TGraph(vNData,x,y); + +// draw graph + vC1 = new TCanvas("vC1","Smooth Regression",200,10,900,700); + vC1->Divide(2,3); + +// Kernel Smoother +// create new kernel smoother and smooth data with bandwidth = 2.0 + TGraphSmooth *gs = new TGraphSmooth("normal"); + grout = gs->SmoothKern(grin,"normal",2.0); + DrawSmooth(1,"Kernel Smoother: bandwidth = 2.0","times","accel"); + +// redraw ksmooth with bandwidth = 5.0 + grout = gs->SmoothKern(grin,"normal",5.0); + DrawSmooth(2,"Kernel Smoother: bandwidth = 5.0","",""); + +// Lowess Smoother +// create new lowess smoother and smooth data with fraction f = 2/3 + grout = gs->SmoothLowess(grin,"",0.67); + DrawSmooth(3,"Lowess: f = 2/3","",""); + +// redraw lowess with fraction f = 0.2 + grout = gs->SmoothLowess(grin,"",0.2); + DrawSmooth(4,"Lowess: f = 0.2","",""); + +// Super Smoother +// create new super smoother and smooth data with default bass = 0 and span = 0 + grout = gs->SmoothSuper(grin,"",0,0); + DrawSmooth(5,"Super Smoother: bass = 0","",""); + +// redraw supsmu with bass = 3 (smoother curve) + grout = gs->SmoothSuper(grin,"",3); + DrawSmooth(6,"Super Smoother: bass = 3","",""); + +// cleanup + delete [] x; + delete [] y; + delete gs; +} diff --git a/tutorials/visualisation/graphs/gr016_struct.C b/tutorials/visualisation/graphs/gr016_struct.C new file mode 100644 index 0000000000000..e584e41cddd9f --- /dev/null +++ b/tutorials/visualisation/graphs/gr016_struct.C @@ -0,0 +1,68 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// Draw a simple graph structure. +/// The graph layout is made using graphviz. This macro creates some +/// nodes and edges and change a few graphical attributes on some of them. +/// +/// \macro_image +/// \macro_code +/// \note For this to work, ROOT has to be compiled with gviz ON +/// \author Olivier Couet + +TCanvas* gr016_struct() +{ + #if __has_include("TGraphStruct.h") // handy check on whether gviz was installed + TGraphStruct *gs = new TGraphStruct(); + + // create some nodes and put them in the graph in one go ... + TGraphNode *n0 = gs->AddNode("n0","Node 0"); + TGraphNode *n1 = gs->AddNode("n1","First node"); + TGraphNode *n2 = gs->AddNode("n2","Second node"); + TGraphNode *n3 = gs->AddNode("n3","Third node"); + TGraphNode *n4 = gs->AddNode("n4","Fourth node"); + TGraphNode *n5 = gs->AddNode("n5","5th node"); + TGraphNode *n6 = gs->AddNode("n6","Node number six"); + TGraphNode *n7 = gs->AddNode("n7","Node 7"); + TGraphNode *n8 = gs->AddNode("n8","Node 8"); + TGraphNode *n9 = gs->AddNode("n9","Node 9"); + + n4->SetTextSize(0.03); + n6->SetTextSize(0.03); + n2->SetTextSize(0.04); + + n3->SetTextFont(132); + + n0->SetTextColor(kRed); + + n9->SetFillColor(kRed-10); + n0->SetFillColor(kYellow-9); + n7->SetFillColor(kViolet-9); + + // some edges ... + gs->AddEdge(n0,n1)->SetLineColor(kRed); + TGraphEdge *e06 = gs->AddEdge(n0,n6); + e06->SetLineColor(kRed-3); + e06->SetLineWidth(4); + gs->AddEdge(n1,n7); + gs->AddEdge(n4,n6); + gs->AddEdge(n3,n9); + gs->AddEdge(n6,n8); + gs->AddEdge(n7,n2); + gs->AddEdge(n8,n3); + gs->AddEdge(n2,n3); + gs->AddEdge(n9,n0); + gs->AddEdge(n1,n4); + gs->AddEdge(n1,n6); + gs->AddEdge(n2,n5); + gs->AddEdge(n3,n6); + gs->AddEdge(n4,n5); + + TCanvas *c = new TCanvas("c","c",800,600); + c->SetFillColor(38); + gs->Draw(); + return c; + #else + return new TCanvas("c","c",800,600); + #endif +} diff --git a/tutorials/visualisation/graphs/gtime.C b/tutorials/visualisation/graphs/gr017_time.C similarity index 75% rename from tutorials/visualisation/graphs/gtime.C rename to tutorials/visualisation/graphs/gr017_time.C index ef25076f2a1d4..e1968a565f67f 100644 --- a/tutorials/visualisation/graphs/gtime.C +++ b/tutorials/visualisation/graphs/gr017_time.C @@ -1,11 +1,10 @@ /// \file /// \ingroup tutorial_graphs /// \notebook -/// Example of TGraphTime. +/// Example of TGraphTime. See the [TGraphTime documentation](https://root.cern/doc/master/classTGraphTime.html) /// /// \macro_image /// \macro_code -/// /// \author Rene Brun #include "TCanvas.h" @@ -16,7 +15,7 @@ #include "TGraphTime.h" #include -void gtime(Int_t nsteps = 500, Int_t np = 100) +void gr017_time(Int_t nsteps = 500, Int_t np = 100) { if (np > 1000) np = 1000; @@ -60,14 +59,23 @@ void gtime(Int_t nsteps = 500, Int_t np = 100) g->Draw(); // save object as animated gif - // g->SaveAnimatedGif("gtime.gif"); + // g->SaveAnimatedGif("gr17_time.gif"); // save object to a file +<<<<<<<< HEAD:tutorials/visualisation/graphs/gtime.C auto f = TFile::Open("gtime.root", "recreate"); +======== + auto f = TFile::Open("gr17_time.root","recreate"); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr017_time.C f->WriteObject(g, "g"); delete f; // to view this object in another session do +<<<<<<<< HEAD:tutorials/visualisation/graphs/gtime.C // TFile::Open("gtime.root"); // g->Draw(); +======== + // TFile::Open("gr17_time.root"); + // g->Draw(); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr017_time.C } diff --git a/tutorials/visualisation/graphs/gtime2.C b/tutorials/visualisation/graphs/gr018_time2.C similarity index 89% rename from tutorials/visualisation/graphs/gtime2.C rename to tutorials/visualisation/graphs/gr018_time2.C index 1fac28ff1508c..d0c1aa59a817f 100644 --- a/tutorials/visualisation/graphs/gtime2.C +++ b/tutorials/visualisation/graphs/gr018_time2.C @@ -4,9 +4,10 @@ /// Example of TGraphTime showing how the class could be used to visualize /// a set of particles with their time stamp in a MonteCarlo program. /// +/// See the [TGraphTime documentation](https://root.cern/doc/master/classTGraphTime.html) +/// /// \macro_image /// \macro_code -/// /// \author Rene Brun #include "TRandom3.h" @@ -17,7 +18,7 @@ #include "TGraphTime.h" #include -void gtime2(Int_t nsteps = 200, Int_t np = 5000) +void gr018_time2(Int_t nsteps = 200, Int_t np = 5000) { if (np > 5000) np = 5000; @@ -56,8 +57,8 @@ void gtime2(Int_t nsteps = 200, Int_t np = 5000) g->Draw(); - // store object as animated gif - // g->SaveAnimatedGif("gtime2.gif"); + // save object as animated gif + // g->SaveAnimatedGif("gr18_time2.gif"); // start animation, can be stopped with g->Animate(kFALSE); // g->Animate(); diff --git a/tutorials/visualisation/graphs/gr101_shade_area.C b/tutorials/visualisation/graphs/gr101_shade_area.C new file mode 100644 index 0000000000000..44353796b5e47 --- /dev/null +++ b/tutorials/visualisation/graphs/gr101_shade_area.C @@ -0,0 +1,43 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// Show how to shade an area between two graphs. +/// +/// \macro_image +/// \macro_code +/// +/// \author Rene Brun + +void gr101_shade_area() { + TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500); + + c1->SetGrid(); + c1->DrawFrame(0,0,2.2,12); + + const Int_t n = 20; + Double_t x[n], y[n],ymin[n], ymax[n]; + Int_t i; + for (i=0;iSetPoint(i,x[i],ymax[i]); + grshade->SetPoint(n+i,x[n-i-1],ymin[n-i-1]); + } + grshade->SetFillStyle(3013); + grshade->SetFillColor(16); + grshade->Draw("f"); //Draw the shaded area with "f" option (filled graph) + grmin->Draw("l"); + grmax->Draw("l"); + gr->SetLineWidth(4); + gr->SetMarkerColor(4); + gr->SetMarkerStyle(21); + gr->Draw("CP"); +} diff --git a/tutorials/visualisation/graphs/gr102_reverse_axis.C b/tutorials/visualisation/graphs/gr102_reverse_axis.C new file mode 100644 index 0000000000000..b141e86d18597 --- /dev/null +++ b/tutorials/visualisation/graphs/gr102_reverse_axis.C @@ -0,0 +1,32 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// 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. +/// +/// \macro_image +/// \macro_code +/// +/// \author Olivier Couet + +void gr102_reverse_axis() { + auto c = new TCanvas("c","Reversed graphs",0,0,900,400); + c->Divide(2,1); //Create a canvas with a 2x1 grid layout + + auto gr = new TGraph(); + gr->GetXaxis()->SetNdivisions(514); + gr->GetYaxis()->SetNdivisions(514); + gr->SetMarkerStyle(kCircle); + gr->SetMarkerColor(kBlue); + gr->SetLineColor(kRed); + gr->SetPoint(0,5,5); + gr->SetPoint(1,9,9); + gr->SetPoint(2,14,14); + + c->cd(1); + gPad->SetGrid(); + gr->Draw("a pl "); //Plot with axis ("a") and line+points ("pl") + + c->cd(2); + gPad->SetGrid(); + gr->Draw("a pl rx ry "); //Plot with axis ("a") and line+points ("pl") with reverse X and Y axes +} diff --git a/tutorials/visualisation/graphs/gr103_zones.C b/tutorials/visualisation/graphs/gr103_zones.C new file mode 100644 index 0000000000000..711acf6441b53 --- /dev/null +++ b/tutorials/visualisation/graphs/gr103_zones.C @@ -0,0 +1,58 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// Example of script showing how to divide a canvas +/// into adjacent subpads + axis labels on the top and right side +/// of the pads. +/// +/// See the [Divide documentation](https://root.cern/doc/master/classTPad.html#a2714ddd7ba72d5def84edc1fbaea8658) +/// +/// Note that the last 2 arguments in +/// `c1->Divide(2,2,0,0)` +/// define 0 space between the pads. With this, the axis labels where the pads +/// touch may be cut, as in this tutorial. To avoid this, either add some spacing +/// between pads (instead of 0) or change the limits of the plot in the pad (histos +/// in this tutorial). E.g. `h3` could be defined as +/// `TH2F *h3 = new TH2F("h3","test3",10,0,1,22,-1.1,1.1);` +/// but note that this can change the displayed axis labels (requiring SetNdivisions +/// to readjust). +/// +/// SetLabelOffset changes the (perpendicular) distance to the axis. The label +/// position along the axis cannot be changed +/// +/// \macro_image +/// \macro_code +/// \author Rene Brun + +<<<<<<<< HEAD:tutorials/visualisation/graphs/zones.C +void zones() +{ + TCanvas *c1 = new TCanvas("c1", "multipads", 900, 700); +======== +void gr103_zones() { + TCanvas *c1 = new TCanvas("c1","multipads",900,700); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr103_zones.C + gStyle->SetOptStat(0); + c1->Divide(2, 2, 0, 0); + TH2F *h1 = new TH2F("h1", "test1", 10, 0, 1, 20, 0, 20); + TH2F *h2 = new TH2F("h2", "test2", 10, 0, 1, 20, 0, 100); + TH2F *h3 = new TH2F("h3", "test3", 10, 0, 1, 20, -1, 1); + TH2F *h4 = new TH2F("h4", "test4", 10, 0, 1, 20, 0, 1000); + + c1->cd(1); + gPad->SetTickx(2); + h1->Draw(); + + c1->cd(2); + gPad->SetTickx(2); + gPad->SetTicky(2); + h2->GetYaxis()->SetLabelOffset(0.01); + h2->Draw(); + + c1->cd(3); + h3->Draw(); + + c1->cd(4); + gPad->SetTicky(2); + h4->Draw(); +} diff --git a/tutorials/visualisation/graphs/zones.py b/tutorials/visualisation/graphs/gr103_zones.py similarity index 50% rename from tutorials/visualisation/graphs/zones.py rename to tutorials/visualisation/graphs/gr103_zones.py index 14af5fb5a3fc3..71d79b9613c60 100644 --- a/tutorials/visualisation/graphs/zones.py +++ b/tutorials/visualisation/graphs/gr103_zones.py @@ -5,9 +5,22 @@ ## into adjacent subpads + axis labels on the top and right side ## of the pads. Original tutorial by Rene Brun. ## +## See the [Divide documentation](https://root.cern/doc/master/classTPad.html#a2714ddd7ba72d5def84edc1fbaea8658) +## +## Note that the last 2 arguments in +## c1->Divide(2,2,0,0) +## define 0 space between the pads. With this, the axis labels where the pads +## touch may be cut, as in this tutorial. To avoid this, either add some spacing +## between pads (instead of 0) or change the limits of the plot in the pad (histos +## in this tutorial). E.g. h3 could be defined as +## TH2F *h3 = new TH2F("h3","test3",10,0,1,22,-1.1,1.1); +## but note that this can change the displayed axis labels (requiring SetNdivisions +## to readjust). +## +## SetLabelOffset changes the (perpendicular) distance to the axis. The label +## position along the axis cannot be changed ## \macro_image ## \macro_code -## ## \author Alberto Ferro import ROOT diff --git a/tutorials/visualisation/graphs/graphpalettecolor.C b/tutorials/visualisation/graphs/gr104_palettecolor.C similarity index 83% rename from tutorials/visualisation/graphs/graphpalettecolor.C rename to tutorials/visualisation/graphs/gr104_palettecolor.C index bfd7b1222d750..64fe9d235a234 100644 --- a/tutorials/visualisation/graphs/graphpalettecolor.C +++ b/tutorials/visualisation/graphs/gr104_palettecolor.C @@ -12,14 +12,19 @@ /// and filled area. The graphs are drawn with curves (`C` option) and one can see /// the color of each graph is picked inside the palette `kSolar`. The /// same is visible on filled polygons in the automatically built legend. +/// To have more control on the legend, it can be created manually, see the graph +/// tutorial gr111_legend.C /// /// \macro_image /// \macro_code -/// /// \author Olivier Couet +<<<<<<<< HEAD:tutorials/visualisation/graphs/graphpalettecolor.C void graphpalettecolor() { +======== +void gr104_palettecolor () { +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr104_palettecolor.C gStyle->SetOptTitle(kFALSE); gStyle->SetPalette(kSolar); @@ -53,6 +58,7 @@ void graphpalettecolor() g5->SetLineWidth(3); g5->SetMarkerStyle(kFullSquare); + // The Draw option "A" (draw axes) is needed (only) for the first drawn graph g1->Draw("CA* PLC PFC"); g2->Draw("PC PLC PFC"); g3->Draw("PC PLC PFC"); diff --git a/tutorials/visualisation/graphs/multigraphpalettecolor.C b/tutorials/visualisation/graphs/gr105_multigraphpalettecolor.C similarity index 92% rename from tutorials/visualisation/graphs/multigraphpalettecolor.C rename to tutorials/visualisation/graphs/gr105_multigraphpalettecolor.C index 2da75277bc5fd..6c05a0681893c 100644 --- a/tutorials/visualisation/graphs/multigraphpalettecolor.C +++ b/tutorials/visualisation/graphs/gr105_multigraphpalettecolor.C @@ -4,7 +4,7 @@ /// Palette coloring for multi-graphs is activated thanks to the options `PFC` /// (Palette Fill Color), `PLC` (Palette Line Color) and `AMC` (Palette Marker Color). /// When one of these options is given to `TMultiGraph::Draw` the `TGraph`s in the -/// `TMultiGraph`get their color from the current color palette defined by +/// `TMultiGraph` get their color from the current color palette defined by /// `gStyle->SetPalette(...)`. The color is determined according to the number of /// `TGraph`s. /// @@ -13,10 +13,9 @@ /// /// \macro_image /// \macro_code -/// /// \author Olivier Couet -void multigraphpalettecolor() +void gr105_multigraphpalettecolor() { auto mg = new TMultiGraph(); diff --git a/tutorials/visualisation/graphs/exclusiongraph.C b/tutorials/visualisation/graphs/gr106_exclusiongraph.C similarity index 56% rename from tutorials/visualisation/graphs/exclusiongraph.C rename to tutorials/visualisation/graphs/gr106_exclusiongraph.C index 63e1140df85b7..54ff656a5c609 100644 --- a/tutorials/visualisation/graphs/exclusiongraph.C +++ b/tutorials/visualisation/graphs/gr106_exclusiongraph.C @@ -3,14 +3,23 @@ /// \notebook /// Draw three graphs with an exclusion zone. /// +/// The shaded areas are obtained with a fill for the graph and controlled with `SetLineWidth`. +/// `SetLineWidth` for exclusion graphs is explained in the [TGraphPainter documentation](https://root.cern/doc/master/classTGraphPainter.html#GrP2) +/// +/// As the graphs will be superposed on drawing, we add them to a [TMultiGraph](https://root.cern/doc/master/classTMultiGraph.html) and then draw this one. +/// /// \macro_image /// \macro_code -/// /// \author Olivier Couet +<<<<<<<< HEAD:tutorials/visualisation/graphs/exclusiongraph.C TCanvas *exclusiongraph() { TCanvas *c1 = new TCanvas("c1", "Exclusion graphs examples", 200, 10, 600, 400); +======== +void gr106_exclusiongraph() { + TCanvas *c1 = new TCanvas("c1","Exclusion graph examples",200,10,600,400); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr106_exclusiongraph.C c1->SetGrid(); TMultiGraph *mg = new TMultiGraph(); @@ -27,7 +36,12 @@ TCanvas *exclusiongraph() yvalues3[i] = 10 * sin(xvalues1[i]) - 2; } +<<<<<<<< HEAD:tutorials/visualisation/graphs/exclusiongraph.C TGraph *gr1 = new TGraph(n, xvalues1, yvalues1); +======== + // See explanation for SetLineWidth above + TGraph *gr1 = new TGraph(n,xvalues1,yvalues1); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr106_exclusiongraph.C gr1->SetLineColor(2); gr1->SetLineWidth(1504); gr1->SetFillStyle(3005); @@ -48,6 +62,4 @@ TCanvas *exclusiongraph() mg->Add(gr2); mg->Add(gr3); mg->Draw("AC"); - - return c1; } diff --git a/tutorials/visualisation/graphs/gr107_exclusiongraph2.C b/tutorials/visualisation/graphs/gr107_exclusiongraph2.C new file mode 100644 index 0000000000000..796b106cbd161 --- /dev/null +++ b/tutorials/visualisation/graphs/gr107_exclusiongraph2.C @@ -0,0 +1,162 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// Draw several graphs with exclusion zones. +/// The shaded areas are obtained with a fill for the graph and controlled with `SetLineWidth`. +/// `SetLineWidth` for exclusion graphs is explained in the [TGraphPainter documentation](https://root.cern/doc/master/classTGraphPainter.html#GrP2) +/// +/// The graphs are drawn superposed, with help of an empty histogram that defines the axes, so we must make sure that the axis limits are adequate for all graphs. Notice that only the first drawn graph needs the "A" (draw axes) option. Alternatively, one could add the graphs to a TMultiGraph, which automatically defines the appropriate limits; see the gr106_exclusiongraph.C tutorial. +/// +/// We add some text to the plot with [TLatex](https://root.cern/doc/master/classTLatex.html). Notice that the TLatex text is drawn on the current pad/canvas and does not need, nor have, a "same" option. +/// +/// \macro_image +/// \macro_code +/// \author Olivier Couet + +void gr107_exclusiongraph2() +{ + TCanvas *c = new TCanvas("c","Charged Higgs L300 Contour",0,0,700,700); + c->SetTickx(); + c->SetTicky(); + c->SetGridx(); + c->SetGridy(); + + // Frame to define the axis limits (50 to 500 and 1 to 50) + TH1 *frame = new TH1F("frame","",1000,50,500); + frame->SetMinimum(1); + frame->SetMaximum(50); + frame->SetDirectory(0); + frame->SetStats(0); + frame->GetXaxis()->SetTitle("m_{A} (GeV)"); + frame->GetXaxis()->SetTickLength(0.02); + frame->GetXaxis()->SetLabelSize(0.03); + frame->GetYaxis()->SetTitle("tan#beta"); + frame->GetYaxis()->SetMoreLogLabels(); + frame->GetYaxis()->SetLabelSize(0.03); + frame->Draw(" "); + c->SetLogy(); + + TGraph *gr1 = new TGraph(10); + gr1->SetFillColor(6); + gr1->SetFillStyle(3005); + gr1->SetLineColor(6); + gr1->SetLineWidth(603); + gr1->SetPoint(0,140,0.5); + gr1->SetPoint(1,130,2.9); + gr1->SetPoint(2,124.677,3.83726); + gr1->SetPoint(3,113.362,6.06903); + gr1->SetPoint(4,108.513,8.00221); + gr1->SetPoint(5,111.746,10.0272); + gr1->SetPoint(6,119.828,12.8419); + gr1->SetPoint(7,135.991,30.0872); + gr1->SetPoint(8,140,40); + gr1->SetPoint(9,135,60); + gr1->Draw("C"); + TLatex *tex = new TLatex(140.841,37.9762, + "#leftarrow t #rightarrow bH^{+}, H^{+} #rightarrow #tau#nu"); + tex->SetTextColor(6); + tex->Draw(); + + TGraph *gr2 = new TGraph(15); + gr2->SetName("Graph"); + gr2->SetTitle("Graph"); + gr2->SetFillColor(1); + gr2->SetFillStyle(3005); + gr2->SetLineWidth(3); + gr2->SetPoint(0,499.192,3.02622); + gr2->SetPoint(1,427.748,3.06233); + gr2->SetPoint(2,358.244,3.10722); + gr2->SetPoint(3,305.711,3.24589); + gr2->SetPoint(4,244.289,3.36617); + gr2->SetPoint(5,206.304,3.7544); + gr2->SetPoint(6,178.017,4.50347); + gr2->SetPoint(7,148.114,6.20297); + gr2->SetPoint(8,131.142,8.00221); + gr2->SetPoint(9,111.746,8.48188); + gr2->SetPoint(10,102.047,9.52921); + gr2->SetPoint(11,96.3901,13.2212); + gr2->SetPoint(12,92.3491,19.0232); + gr2->SetPoint(13,90.7328,26.3935); + gr2->SetPoint(14,93.1573,50.4385); + gr2->Draw("L"); + tex = new TLatex(346.929,6.62281,"ATLAS"); + tex->SetLineWidth(2); + tex->Draw(); + tex = new TLatex(328.341,5.24703,"#intLdt = 300 fb^{-1}"); + tex->SetTextSize(0.0297619); + tex->SetLineWidth(2); + tex->Draw(); + tex = new TLatex(340.463,4.1874,"Maximal mixing"); + tex->SetTextSize(0.0297619); + tex->SetLineWidth(2); + tex->Draw(); + tex = new TLatex(413.2,2.51608,"LEP 2000"); + tex->SetTextSize(0.0297619); + tex->SetLineWidth(2); + tex->Draw(); + + TGraph *gr3 = new TGraph(10); + gr3->SetName("Graph"); + gr3->SetTitle("Graph"); + gr3->SetFillColor(2); + gr3->SetFillStyle(3004); + gr3->SetLineColor(2); + gr3->SetLineWidth(603); + gr3->SetPoint(0,176.84,10.7499); + gr3->SetPoint(1,190.575,11.9912); + gr3->SetPoint(2,211.58,12.7108); + gr3->SetPoint(3,243.088,12.3457); + gr3->SetPoint(4,279.443,12.6185); + gr3->SetPoint(5,302.065,12.9916); + gr3->SetPoint(6,331.957,13.7713); + gr3->SetPoint(7,369.928,14.2821); + gr3->SetPoint(8,425.673,16.1651); + gr3->SetPoint(9,499.192,18.1635); + gr3->Draw("C"); + tex = new TLatex(188.151,9.36035, + "gb #rightarrow tH^{+}, H^{+} #rightarrow #tau#nu"); + tex->SetTextColor(2); + tex->Draw(); + + TGraph *gr4 = new TGraph(10); + gr4->SetName("Graph"); + gr4->SetTitle("Graph"); + gr4->SetFillColor(4); + gr4->SetFillStyle(3004); + gr4->SetLineColor(4); + gr4->SetLineWidth(-603); + gr4->SetPoint(0,178.456,2.91797); + gr4->SetPoint(1,200.269,3.40033); + gr4->SetPoint(2,229.354,3.96243); + gr4->SetPoint(3,249.551,4.07959); + gr4->SetPoint(4,269.749,3.71097); + gr4->SetPoint(5,298.025,3.09308); + gr4->SetPoint(6,341.652,2.89679); + gr4->SetPoint(7,378.007,2.57808); + gr4->SetPoint(8,441.023,2.16454); + gr4->SetPoint(9,499.677,1.76145); + gr4->Draw("C"); + tex = new TLatex(165.,1.15498, + "gb #rightarrow tH^{+}, H^{+} #rightarrow tb"); + tex->SetTextColor(4); + tex->Draw(); + + TGraph *gr5 = new TGraph(10); + gr5->SetName("Graph"); + gr5->SetTitle("Graph"); + gr5->SetFillColor(4); + gr5->SetFillStyle(3004); + gr5->SetLineColor(4); + gr5->SetLineWidth(603); + gr5->SetPoint(0,152.603,23.0996); + gr5->SetPoint(1,188.151,18.8373); + gr5->SetPoint(2,239.048,15.2499); + gr5->SetPoint(3,264.901,15.8156); + gr5->SetPoint(4,299.641,18.8373); + gr5->SetPoint(5,334.381,20.7085); + gr5->SetPoint(6,360.233,22.4362); + gr5->SetPoint(7,396.589,24.4859); + gr5->SetPoint(8,433.752,25.7669); + gr5->SetPoint(9,499.192,27.3132); + gr5->Draw("C"); +} diff --git a/tutorials/visualisation/graphs/timeSeriesFromCSV.C b/tutorials/visualisation/graphs/gr108_timeSeriesFromCSV.C similarity index 87% rename from tutorials/visualisation/graphs/timeSeriesFromCSV.C rename to tutorials/visualisation/graphs/gr108_timeSeriesFromCSV.C index f718ceea69882..789702c160dc2 100644 --- a/tutorials/visualisation/graphs/timeSeriesFromCSV.C +++ b/tutorials/visualisation/graphs/gr108_timeSeriesFromCSV.C @@ -7,10 +7,9 @@ /// /// \macro_image /// \macro_code -/// /// \authors Danilo Piparo, Olivier Couet -void timeSeriesFromCSV() +void gr108_timeSeriesFromCSV() { // Open the data file. This csv contains the usage statistics of a CERN IT // service, SWAN, during two weeks. We would like to plot this data with @@ -20,7 +19,8 @@ void timeSeriesFromCSV() dir.ReplaceAll("/./", "/"); FILE *f = fopen(Form("%sSWAN2017.dat", dir.Data()), "r"); - // Create the time graph + // Create the time graph. In this example, we don't specify anything about it, + // and data points will be added with SetPoint (the first point has index 0) auto g = new TGraph(); g->SetTitle("SWAN Users during July 2017;Time;Number of Sessions"); @@ -49,7 +49,7 @@ void timeSeriesFromCSV() g->Draw("al"); g->GetYaxis()->CenterTitle(); - // Make the X axis labelled with time. + // Make the X axis labelled with time auto xaxis = g->GetXaxis(); xaxis->SetTimeDisplay(1); xaxis->CenterTitle(); diff --git a/tutorials/visualisation/graphs/timeSeriesFromCSV.py b/tutorials/visualisation/graphs/gr108_timeSeriesFromCSV.py similarity index 90% rename from tutorials/visualisation/graphs/timeSeriesFromCSV.py rename to tutorials/visualisation/graphs/gr108_timeSeriesFromCSV.py index 6345361c9bb3b..c678659553cb5 100644 --- a/tutorials/visualisation/graphs/timeSeriesFromCSV.py +++ b/tutorials/visualisation/graphs/gr108_timeSeriesFromCSV.py @@ -7,7 +7,6 @@ ## ## \macro_image ## \macro_code -## ## \authors Danilo Piparo, Olivier Couet import ROOT @@ -20,7 +19,8 @@ dirName= dirName.replace("/./", "/") inputFileName = "%s/SWAN2017.dat" %dirName -# Create the time graph +# Create the time graph. In this example, we don't specify anything about it, +# and data points will be added with SetPoint (the first point has index 0) g = ROOT.TGraph() g.SetTitle("SWAN Users during July 2017;Time;Number of Sessions") diff --git a/tutorials/visualisation/graphs/timeSeriesFromCSV_TDF.C b/tutorials/visualisation/graphs/gr109_timeSeriesFromCSV_TDF.C similarity index 81% rename from tutorials/visualisation/graphs/timeSeriesFromCSV_TDF.C rename to tutorials/visualisation/graphs/gr109_timeSeriesFromCSV_TDF.C index 5a3ce3d9836b4..49be1f566b966 100644 --- a/tutorials/visualisation/graphs/timeSeriesFromCSV_TDF.C +++ b/tutorials/visualisation/graphs/gr109_timeSeriesFromCSV_TDF.C @@ -4,11 +4,10 @@ /// 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. -/// We exploit the TDataFrame for reading from the file +/// We exploit the TDataFrame for reading from the file. See the [RDataFrame documentation](https://root.cern/doc/master/classROOT_1_1RDataFrame.html) and [RDataFrame tutorials](https://root.cern/doc/master/group__tutorial__dataframe.html) /// /// \macro_image /// \macro_code -/// /// \authors Danilo Piparo, Olivier Couet void timeSeriesFromCSV_TDF() @@ -30,7 +29,8 @@ void timeSeriesFromCSV_TDF() auto timeStamps = d.Take("TimeStamp"); auto values = d.Take("Value"); - // Create the time graph + // Create the time graph. In this example, we provide to the TGraph constructor + // the number of (pairs of) points and all the x and y values auto g = new TGraph(values->size(), timeStamps->data(), values->data()); g->SetTitle("SWAN Users during July 2017;Time;Number of Sessions"); @@ -44,7 +44,7 @@ void timeSeriesFromCSV_TDF() g->Draw("al"); g->GetYaxis()->CenterTitle(); - // Make the X axis labelled with time. + // Make the X axis labelled with time auto xaxis = g->GetXaxis(); xaxis->SetTimeDisplay(1); xaxis->CenterTitle(); diff --git a/tutorials/visualisation/graphs/gr110_logscale.C b/tutorials/visualisation/graphs/gr110_logscale.C new file mode 100644 index 0000000000000..d33395fd16e4c --- /dev/null +++ b/tutorials/visualisation/graphs/gr110_logscale.C @@ -0,0 +1,43 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// +/// This tutorial demonstrates how to set a logarithmic scale for the axes of a graph using the `SetLogScale()` method. +/// The logarithmic scale can be applied to either the x-axis, the y-axis, or both axes at the same time. +/// When using a logarithmic scale, the data must be positive since the logarithm is undefined for non-positive values and zero. +/// +/// \macro_image +/// \macro_code +/// \date 25/11/2024 +/// \author Emanuele Chiamulera + +void gr110_logscale { + + auto c = new TCanvas("c","Reversed graphs",0,0,900,400); + c->Divide(2,1); + c->cd(1); + + const Int_t n = 6; //Fill the arrays x and y with the data points + Double_t x[n], y[n]; + for (Int_t i=0;iSetLineColor(2); + gr1->SetLineWidth(4); + gr1->SetMarkerColor(4); + gr1->SetMarkerStyle(21); + gr1->SetTitle("Graph without log scale"); + gr1->DrawClone("ACP"); + + //The logarithmic scale setting can also be done in a ROOT interactive session. + c->cd(2); + gPad->SetLogy(); + //gPad->SetLogx(); Uncomment this line if log scale is needed on both axes + gr1->SetTitle("Graph with y log scale"); + gr1->Draw("ACP"); + +} \ No newline at end of file diff --git a/tutorials/visualisation/graphs/gr111_legend.C b/tutorials/visualisation/graphs/gr111_legend.C new file mode 100644 index 0000000000000..2c154d8b01656 --- /dev/null +++ b/tutorials/visualisation/graphs/gr111_legend.C @@ -0,0 +1,42 @@ +/// \file +/// \ingroup tutorial_graphs +/// \notebook +/// +/// Simple graph with legend. For more details on TLegend [see documenation](https://root.cern/doc/master/classTLegend.html) +/// +/// +/// \macro_image +/// \macro_code +/// \date 25/11/2024 +/// \author Emanuele Chiamulera + +void gr111_legend() { + + auto c = new TCanvas("c","", 900, 800); + c->SetGrid(); + + const Int_t n = 5; + Double_t x[n] = {-3.00, -2.68, -2.36, -2.05, -1.73}; + Double_t y1[n] = {-0.98, -0.89, -0.71, -0.46, -0.16}; + Double_t y2[n] = {-2.98, -2.89, -2.71, -2.46, -2.16}; + + + TGraph *gr1 = new TGraph(n, x, y1); //Create the graph + gr1->SetLineColor(2); + gr1->SetLineWidth(4); + gr1->SetMarkerColor(4); + gr1->SetMarkerStyle(21); + gr1->SetTitle("Graph with legend"); + + TLegend *legend = new TLegend(0.1,0.7,0.38,0.9); //Create the TLegend object and define it's position + legend->SetHeader("Legend title", "C"); //"C" Center alignment for the header ("L" Left and "R" Right) + legend->SetFillColor(kWhite); + legend->SetBorderSize(1); + legend->SetTextSize(0.04); + legend->AddEntry(gr1, "Data points", "lp"); // "p" for point marker, "l" for line, "e" for error bars if TGraphError is used. + + gr1->Draw(""); + + // Draw the legend + legend->Draw(); +} diff --git a/tutorials/visualisation/graphs/graphreverse.C b/tutorials/visualisation/graphs/gr112_err_reverse_axis.C similarity index 58% rename from tutorials/visualisation/graphs/graphreverse.C rename to tutorials/visualisation/graphs/gr112_err_reverse_axis.C index a386809fc0e4a..a37fe4fb8788a 100644 --- a/tutorials/visualisation/graphs/graphreverse.C +++ b/tutorials/visualisation/graphs/gr112_err_reverse_axis.C @@ -1,36 +1,34 @@ /// \file /// \ingroup tutorial_graphs /// \notebook -/// This example test all the various case of reverse graphs -/// combined with logarithmic scale. +/// This example tests all the various case of reverse graphs obtained with Draw("a pl rx ry "), where rx and ry refere to the reversing of x and y axis. /// /// \macro_image /// \macro_code /// /// \author Olivier Couet -void graphreverse() -{ - auto c = new TCanvas("c", "Reversed graphs", 0, 0, 900, 900); - c->Divide(3, 3); +void gr102_err_reverse_axis() { + auto c = new TCanvas("c","Reversed graphs",0,0,900,900); + c->Divide(3,3); - // TGraphErrors + //TGraphErrors (first row example) auto graphe = new TGraphErrors(); graphe->GetXaxis()->SetNdivisions(514); graphe->GetYaxis()->SetNdivisions(514); graphe->SetMarkerStyle(kCircle); - graphe->SetPoint(0, 5, 5); - graphe->SetPointError(0, 1, 3); - graphe->SetPoint(1, 9, 9); - graphe->SetPointError(1, 1, 3); + graphe->SetPoint(0,5,5); + graphe->SetPointError(0,1,3); + graphe->SetPoint(1,9,9); + graphe->SetPointError(1,1,3); c->cd(1); gPad->SetGrid(); - graphe->Draw("a pl "); + graphe->Draw("a pl "); //Plot with axis ("a") and line+points ("pl") c->cd(2); gPad->SetGrid(); - graphe->Draw("a pl rx ry "); + graphe->Draw("a pl rx ry "); //Plot with axis ("a") and line+points ("pl") with reverse X and Y axes c->cd(3); gPad->SetGrid(); @@ -38,17 +36,17 @@ void graphreverse() gPad->SetLogy(); graphe->GetXaxis()->SetMoreLogLabels(); graphe->GetYaxis()->SetMoreLogLabels(); - graphe->Draw("a pl rx ry"); + graphe->Draw("a pl rx ry"); //Plot with reverse axis and log scale - // TGraphAsymmErrors + //TGraphAsymmErrors (second row example) auto graphae = new TGraphAsymmErrors(); graphae->GetXaxis()->SetNdivisions(514); graphae->GetYaxis()->SetNdivisions(514); graphae->SetMarkerStyle(kCircle); - graphae->SetPoint(0, 5, 5); - graphae->SetPointError(0, 1, 3, 3, 1); - graphae->SetPoint(1, 9, 9); - graphae->SetPointError(1, 1, 3, 1, 3); + graphae->SetPoint(0,5,5); + graphae->SetPointError(0,1,3,3,1); + graphae->SetPoint(1,9,9); + graphae->SetPointError(1,1,3,1,3); c->cd(4); gPad->SetGrid(); @@ -66,15 +64,15 @@ void graphreverse() graphae->GetYaxis()->SetMoreLogLabels(); graphae->Draw("a pl rx ry"); - // TGraphBentErrors + //TGraphBentErrors (third row example) auto graphbe = new TGraphBentErrors(); graphbe->GetXaxis()->SetNdivisions(514); graphbe->GetYaxis()->SetNdivisions(514); graphbe->SetMarkerStyle(kCircle); - graphbe->SetPoint(0, 5, 5); - graphbe->SetPointError(0, 1, 3, 3, 1, .5, .2, .5, .2); - graphbe->SetPoint(1, 9, 9); - graphbe->SetPointError(1, 1, 3, 1, 3, -.5, -.2, -.5, -.2); + graphbe->SetPoint(0,5,5); + graphbe->SetPointError(0,1,3,3,1,.5,.2,.5,.2); + graphbe->SetPoint(1,9,9); + graphbe->SetPointError(1,1,3,1,3,-.5,-.2,-.5,-.2); c->cd(7); gPad->SetGrid(); @@ -91,4 +89,4 @@ void graphreverse() graphbe->GetXaxis()->SetMoreLogLabels(); graphbe->GetYaxis()->SetMoreLogLabels(); graphbe->Draw("a pl rx ry"); -} +} \ No newline at end of file diff --git a/tutorials/visualisation/graphs/waves.C b/tutorials/visualisation/graphs/gr201_waves.C similarity index 59% rename from tutorials/visualisation/graphs/waves.C rename to tutorials/visualisation/graphs/gr201_waves.C index c0b6344070fe2..fd2c499c9ccb7 100644 --- a/tutorials/visualisation/graphs/waves.C +++ b/tutorials/visualisation/graphs/gr201_waves.C @@ -1,11 +1,11 @@ /// \file /// \ingroup tutorial_graphs /// \notebook -/// Hint: Spherical waves +/// Draw spherical waves interference. Two closed TGraphs filled with white are used +/// here to draw triangles on top of a 2D function in order to hide parts of it. /// /// \macro_image /// \macro_code -/// /// \author Otto Schaile #include "TROOT.h" @@ -49,10 +49,17 @@ Double_t result(Double_t *x, Double_t *par) } //_____________________________________________________________ +<<<<<<<< HEAD:tutorials/visualisation/graphs/waves.C void waves(Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) { TCanvas *c1 = new TCanvas("waves", "A double slit experiment", 300, 40, 1004, 759); c1->Range(0, -10, 30, 10); +======== +void gr201_waves( Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) +{ + TCanvas *c1 = new TCanvas("gr201_waves", "A double slit experiment", 300, 40, 1004, 759); + c1->Range(0, -10, 30, 10); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr201_waves.C c1->SetFillColor(0); TPad *pad = new TPad("pr", "pr", 0.5, 0, 1., 1); pad->Range(0, -10, 15, 10); @@ -61,15 +68,25 @@ void waves(Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) const Int_t colNum = 30; Int_t palette[colNum]; for (Int_t i = 0; i < colNum; i++) { +<<<<<<<< HEAD:tutorials/visualisation/graphs/waves.C Float_t level = 1. * i / colNum; palette[i] = TColor::GetColor((Float_t)TMath::Power(level, 0.3), (Float_t)TMath::Power(level, 0.3), (Float_t)0.5 * level); +======== + Float_t level = 1.*i/colNum; + palette[i] = TColor::GetColor((Float_t) TMath::Power(level,0.3), (Float_t) TMath::Power(level,0.3), (Float_t) 0.5*level); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr201_waves.C // palette[i] = 1001+i; } gStyle->SetPalette(colNum, palette); c1->cd(); +<<<<<<<< HEAD:tutorials/visualisation/graphs/waves.C +======== + // For the incoming waves, on the left side, we use a TF2 and increase the number + // of points used for drawing to 200 (default is 100) for better resolution +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr201_waves.C TF2 *f0 = new TF2("ray_source", interference, 0.02, 15, -8, 8, 4); f0->SetParameters(amp, lambda, 0, 0); f0->SetNpx(200); @@ -80,8 +97,10 @@ void waves(Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) TLatex title; title.DrawLatex(1.6, 8.5, "A double slit experiment"); + // Draw 2 white triangles to cover parts of f0, simulating a cone + // (change the fill color to see these) TGraph *graph = new TGraph(4); - graph->SetFillColor(0); + graph->SetFillColor(1); graph->SetFillStyle(1001); graph->SetLineWidth(0); graph->SetPoint(0, 0., 0.1); @@ -91,7 +110,7 @@ void waves(Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) graph->Draw("F"); graph = new TGraph(4); - graph->SetFillColor(0); + graph->SetFillColor(1); graph->SetFillStyle(1001); graph->SetLineWidth(0); graph->SetPoint(0, 0, -0.1); @@ -100,6 +119,7 @@ void waves(Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) graph->SetPoint(3, 0, -0.1); graph->Draw("F"); +<<<<<<<< HEAD:tutorials/visualisation/graphs/waves.C TLine *line = new TLine(15, -10, 15, 0 - 0.5 * d - 0.2); line->SetLineWidth(10); line->Draw(); @@ -109,18 +129,36 @@ void waves(Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) line->Draw(); line = new TLine(15, 0 + 0.5 * d + 0.2, 15, 10); +======== + // To represent the wall with 2 openings, we draw 3 black vertical lines + TLine * line = new TLine(15,-10, 15, 0 - 0.5*d - 0.2); + line->SetLineWidth(10); + line->Draw(); + + line = new TLine(15, 0 - 0.5*d + 0.2, 15, 0 + 0.5*d - 0.2); + line->SetLineWidth(10); + line->Draw(); + + line = new TLine(15, 0 + 0.5*d + 0.2, 15, 10); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr201_waves.C line->SetLineWidth(10); line->Draw(); pad->cd(); +<<<<<<<< HEAD:tutorials/visualisation/graphs/waves.C TF2 *finter = new TF2("interference", interference, 0.01, 14, -10, 10, 4); +======== + // Interference plot, on the centre-right side + TF2 *finter = new TF2("interference",interference, 0.01, 14, -10, 10, 4); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr201_waves.C finter->SetParameters(amp, lambda, d, 1); finter->SetNpx(200); finter->SetNpy(200); finter->SetContour(colNum - 2); finter->Draw("samecol"); + // Some lines TArc arc; arc.SetFillStyle(0); arc.SetLineWidth(2); @@ -134,17 +172,28 @@ void waves(Double_t d = 3, Double_t lambda = 1, Double_t amp = 10) pad->cd(); +<<<<<<<< HEAD:tutorials/visualisation/graphs/waves.C TF2 *fresult = new TF2("result", result, 14, 15, -10, 10, 4); +======== + // Result, on the right edge + TF2 *fresult = new TF2("result",result, 14, 15, -10, 10, 4); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr201_waves.C fresult->SetParameters(amp, lambda, d, 1); fresult->SetNpx(300); fresult->SetNpy(300); fresult->SetContour(colNum - 2); fresult->Draw("samecol"); +<<<<<<<< HEAD:tutorials/visualisation/graphs/waves.C line = new TLine(13.8, -10, 14, 10); line->SetLineWidth(10); line->SetLineColor(0); line->Draw(); +======== + // Vertical white line on the right side + line = new TLine(14,-10, 14, 10); + line->SetLineWidth(10); line->SetLineColor(0); line->Draw(); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr201_waves.C c1->Modified(kTRUE); c1->Update(); c1->SetEditable(kTRUE); diff --git a/tutorials/visualisation/graphs/graphtext.C b/tutorials/visualisation/graphs/gr202_textmarkers.C similarity index 68% rename from tutorials/visualisation/graphs/graphtext.C rename to tutorials/visualisation/graphs/gr202_textmarkers.C index 73c1fe1e76d50..3e5adcc8abe82 100644 --- a/tutorials/visualisation/graphs/graphtext.C +++ b/tutorials/visualisation/graphs/gr202_textmarkers.C @@ -8,12 +8,16 @@ /// /// \macro_image /// \macro_code -/// /// \author Olivier Couet +<<<<<<<< HEAD:tutorials/visualisation/graphs/graphtext.C void graphtext() { TCanvas *c = new TCanvas("c", "A Simple Graph Example with Text", 700, 500); +======== +void gr202_textmarkers() { + TCanvas *c = new TCanvas("c","A Simple Graph Example with Text",700,500); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr202_textmarkers.C c->SetGrid(); const Int_t n = 10; @@ -24,10 +28,17 @@ void graphtext() gr->GetListOfFunctions()->Add(ex); Double_t x, y; +<<<<<<<< HEAD:tutorials/visualisation/graphs/graphtext.C for (Int_t i = 0; i < n; i++) { x = i * 0.1; y = 10 * sin(x + 0.2); gr->SetPoint(i, x, y); +======== + for (Int_t i=0;iSetPoint(i,x,y); +>>>>>>>> 021c32da2b (Rename and comment graphs tutorials):tutorials/visualisation/graphs/gr202_textmarkers.C } gr->Draw("ALP"); } diff --git a/tutorials/visualisation/graphs/hlGraph1.C b/tutorials/visualisation/graphs/gr301_highlight1.C similarity index 89% rename from tutorials/visualisation/graphs/hlGraph1.C rename to tutorials/visualisation/graphs/gr301_highlight1.C index 9d787d7ea22c8..a6c1495afd271 100644 --- a/tutorials/visualisation/graphs/hlGraph1.C +++ b/tutorials/visualisation/graphs/gr301_highlight1.C @@ -1,10 +1,9 @@ /// \file /// \ingroup tutorial_graphs /// -/// This tutorial demonstrates how to use the highlight mode on graph. +/// This tutorial demonstrates how to use the highlight mode on graph, thanks to the TCanvas [HighlightConnect](https://root.cern/doc/master/classTCanvas.html#a462b8dc286a2d29152fefa9b31f89920) method. /// /// \macro_code -/// /// \date March 2018 /// \author Jan Musinsky @@ -28,7 +27,7 @@ void HighlightHisto(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y) } } -void hlGraph1() +void gr301_highlight1() { auto Canvas = new TCanvas("Canvas", "Canvas", 0, 0, 700, 500); Canvas->HighlightConnect("HighlightHisto(TVirtualPad*,TObject*,Int_t,Int_t)"); diff --git a/tutorials/visualisation/graphs/hlGraph2.C b/tutorials/visualisation/graphs/gr302_highlight2.C similarity index 94% rename from tutorials/visualisation/graphs/hlGraph2.C rename to tutorials/visualisation/graphs/gr302_highlight2.C index e1bed89d3d7fe..25551a430c586 100644 --- a/tutorials/visualisation/graphs/hlGraph2.C +++ b/tutorials/visualisation/graphs/gr302_highlight2.C @@ -1,10 +1,9 @@ /// \file /// \ingroup tutorial_graphs /// -/// This tutorial demonstrates how to use the highlight mode on graph. +/// This tutorial demonstrates how to use the highlight mode on graph, thanks to the TCanvas [HighlightConnect](https://root.cern/doc/master/classTCanvas.html#a462b8dc286a2d29152fefa9b31f89920) method. /// /// \macro_code -/// /// \date March 2018 /// \author Jan Musinsky @@ -68,7 +67,7 @@ void HighlightBinId(TVirtualPad *pad, TObject *obj, Int_t ihp, Int_t y) savepad->cd(); } -void hlGraph2() +void gr302_highlight2() { auto dir = gROOT->GetTutorialDir(); dir.Append("/hsimple.C"); diff --git a/tutorials/visualisation/graphs/zdemo.C b/tutorials/visualisation/graphs/gr303_zdemo.C similarity index 99% rename from tutorials/visualisation/graphs/zdemo.C rename to tutorials/visualisation/graphs/gr303_zdemo.C index f30a352de0764..fe140c1cdb0fb 100644 --- a/tutorials/visualisation/graphs/zdemo.C +++ b/tutorials/visualisation/graphs/gr303_zdemo.C @@ -36,7 +36,7 @@ Float_t Z[NMAX], HZ[NMAX], PT[NMAX], INVSIG[NMAX]; void hz_calc(Float_t, Float_t, Float_t, Float_t, Float_t, Float_t); //__________________________________________________________________ -void zdemo() +void gr303_zdemo() { Float_t energ; diff --git a/tutorials/visualisation/graphs/graphApply.C b/tutorials/visualisation/graphs/graphApply.C deleted file mode 100644 index 5f414f61e26d2..0000000000000 --- a/tutorials/visualisation/graphs/graphApply.C +++ /dev/null @@ -1,56 +0,0 @@ -/// \file -/// \ingroup tutorial_graphs -/// \notebook -/// A macro to demonstrate the functionality of TGraph::Apply() method. -/// TGraph::Apply applies a function `f` to all the data TGraph points. -/// `f` may be a 1-D function TF1 or 2-d function TF2. -/// The Y values of the graph are replaced by the new values computed using -/// the function. -/// -/// \macro_image -/// \macro_code -/// -/// \author Miro Helbich - -void graphApply() -{ - const Int_t npoints = 3; - Double_t xaxis[npoints] = {1., 2., 3.}; - Double_t yaxis[npoints] = {10., 20., 30.}; - Double_t errorx[npoints] = {0.5, 0.5, 0.5}; - Double_t errory[npoints] = {5., 5., 5.}; - - Double_t exl[npoints] = {0.5, 0.5, 0.5}; - Double_t exh[npoints] = {0.5, 0.5, 0.5}; - Double_t eyl[npoints] = {5., 5., 5.}; - Double_t eyh[npoints] = {5., 5., 5.}; - - TGraph *gr1 = new TGraph(npoints, xaxis, yaxis); - TGraphErrors *gr2 = new TGraphErrors(npoints, xaxis, yaxis, errorx, errory); - TGraphAsymmErrors *gr3 = new TGraphAsymmErrors(npoints, xaxis, yaxis, exl, exh, eyl, eyh); - TF2 *ff = new TF2("ff", "-1./y"); - - TCanvas *c1 = new TCanvas("c1", "c1"); - c1->Divide(2, 3); - - // TGraph - c1->cd(1); - gr1->DrawClone("A*"); - c1->cd(2); - gr1->Apply(ff); - gr1->Draw("A*"); - - // TGraphErrors - c1->cd(3); - gr2->DrawClone("A*"); - c1->cd(4); - gr2->Apply(ff); - gr2->Draw("A*"); - - // TGraphAsymmErrors - c1->cd(5); - gr3->DrawClone("A*"); - c1->cd(6); - gr3->Apply(ff); - gr3->Draw("A*"); -} diff --git a/tutorials/visualisation/graphs/graphpolar2.C b/tutorials/visualisation/graphs/graphpolar2.C deleted file mode 100644 index 0597a5982a920..0000000000000 --- a/tutorials/visualisation/graphs/graphpolar2.C +++ /dev/null @@ -1,36 +0,0 @@ -/// \file -/// \ingroup tutorial_graphs -/// \notebook -/// Create and draw a polar graph with PI axis -/// -/// \macro_image -/// \macro_code -/// -/// \author Olivier Couet - -void graphpolar2() -{ - auto CPol = new TCanvas("CPol", "TGraphPolar Example", 500, 500); - - Double_t theta[8]; - Double_t radius[8]; - Double_t etheta[8]; - Double_t eradius[8]; - - for (int i = 0; i < 8; i++) { - theta[i] = (i + 1) * (TMath::Pi() / 4.); - radius[i] = (i + 1) * 0.05; - etheta[i] = TMath::Pi() / 8.; - eradius[i] = 0.05; - } - - auto grP1 = new TGraphPolar(8, theta, radius, etheta, eradius); - grP1->SetTitle(""); - - grP1->SetMarkerStyle(20); - grP1->SetMarkerSize(2.); - grP1->SetMarkerColor(4); - grP1->SetLineColor(2); - grP1->SetLineWidth(3); - grP1->Draw("RPE"); // R - radian, P - markers, E - errors -} diff --git a/tutorials/visualisation/graphs/index.md b/tutorials/visualisation/graphs/index.md new file mode 100644 index 0000000000000..c82f81fe2d031 --- /dev/null +++ b/tutorials/visualisation/graphs/index.md @@ -0,0 +1,111 @@ +\addtogroup tutorial_graphs + +@{ +A [TGraph](https://root.cern/doc/master/classTGraph.html) is an object made of two arrays X and Y with npoints each. ROOT can create TGraphs automatically by reading a text file (e.g. CSV), and other methods exist to create them from a function, from another TGraph, a histogram, vectors, arrays, or even by adding pairs of points one by one. + +In addition, ROOT offers multiple variations to basic TGraphs, such as: +- [TGraph2D](https://root.cern/doc/master/classTGraph2D.html) +- [TGraph2DAsymmErrors](https://root.cern/doc/master/classTGraph2DAsymmErrors.html) +- [TGraph2DErrrors](https://root.cern/doc/master/classTGraph2DErrors.html) +- [TGraphAsymmErrors](https://root.cern/doc/master/classTGraphAsymmErrors.html) +- [TGraphBentErrors](https://root.cern/doc/master/classTGraphBentErrors.html) +- [TGraphDelaunay](https://root.cern/doc/master/classTGraphDelaunay.html) +- [TGraphDelaunay2D](https://root.cern/doc/master/classTGraphDelaunay2D.html) +- [TGraphErrors](https://root.cern/doc/master/classTGraphErrors.html) +- [TGraphMultiErrors](https://root.cern/doc/master/classTGraphMultiErrors.html) +- [TGraphPolar](https://root.cern/doc/master/classTGraphPolar.html) +- [TGraphQQ](https://root.cern/doc/master/classTGraphQQ.html) +- [TGraphSmooth](https://root.cern/doc/master/classTGraphSmooth.html) +- [TGraphStruct](https://root.cern/doc/master/classTGraphStruct.html) +- [TGraphTime](https://root.cern/doc/master/classTGraphTime.html) + +TGraphs are painted through the [TGraphPainter](https://root.cern/doc/master/classTGraphPainter.html) or [TGraph2DPainter](https://root.cern/doc/master/classTGraph2DPainter.html) class. As a general remark, TGraphs are not binned, each point is painted individually, and when the "A" draw option is used, ROOT draws a histogram, which can be retrieved with `graph->GetHistogram()` after drawing it, to display a frame with x and y axes. Note that the bins of this histogram do not correspond to the points of the graph (i.e., generally speaking bin 1 is not the same as the x value of point 1, and so on). + +To draw two or more TGraphs superposed, there are two basic approaches: +1. Draw the first one with the option "A" included (so that the axes are drawn), and successively draw the next one/s (without the "A" option). +2. Create a [TMultiGraph](https://root.cern/doc/master/classTMultiGraph.html) and Add all graphs to it, then draw the `TMultiGraph`. + +In the second approach, `TMultiGraph` automatically sets an appropriate scale for the plot so that all graphs are shown. In the first approach, the scale is determined by the graph that was drawn with "A", which may or may not be large enough for all graphs. + +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 +- [Basics: creation and drawing](\ref basics) +- [Formatting: changing/adding elements to the graphs and/or the plots](\ref modfying) +- [Intermediate: more advanced examples](\ref medium) +- [More tutorials](\ref other) + + +[List of all tutorials](\ref alltutorials) +\anchor basics +## Basics + +These examples showscase the creation of different types of graphs and basic ways to plot them. + +| **Tutorial** || **Description** | +|------|--------|-----------------| +| gr001_basic.C | | Create a simple graph from available data or from a file, and draw it. | +| gr002_err_1g.C | | Create and draw a graph with error bars.| +| gr003_err_2gr.C | | Create and draw two graphs with error bars, superposed on the same canvas (not using TMultiGraph). | +| gr004_err_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 colour 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_2Derrorsfit.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 visualise a set of particles with their time stamp in a MonteCarlo program. | + + +\anchor modifying +## Formatting + +These examples show + +| **Tutorial** || **Description** | +|------|--------|-----------------| +| gr101_shade_area.C | | Shows how to shade an area between two graphs. | +| gr102_reverse_axis.C | | How to reverse the points of a graph along x. | +| gr103_zones.C | gr103_zones.py | How to divide a canvas into adjacent subpads, with axis labels on the top and right side of the pads. | +| gr104_palettecolor.C | | Automatically set graph colours from a palette. | +| gr105_multigraphpalettecolor.C | | Automatically set multi-graph colours 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_TDF.C | | Use of the time axis on a TGraph with data read from a text file, but using [RDataFrame](https://root.cern/doc/master/classROOT_1_1RDataFrame.html). | + + +\anchor medium +## Intermediate + +These examples show + +| **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](https://root.cern/doc/master/classTExec.html) function to attach the text to the points. | +| | | | + + +\anchor other +## More tutorials + +These examples show + +| **Tutorial** || **Description** | +|------|--------|-----------------| +| gr301_highlight1.C | | How to use the interactive highlight mode on graph, thanks to the TCanvas [HighlightConnect](https://root.cern/doc/master/classTCanvas.html#a462b8dc286a2d29152fefa9b31f89920) method. | +| gr302_highlight2.C | | How to use the interactive highlight mode on graph, thanks to the TCanvas [HighlightConnect](https://root.cern/doc/master/classTCanvas.html#a462b8dc286a2d29152fefa9b31f89920) method. | +| gr303_zdemo.C | | Example of graphs in log scales with annotations and other advanced plot formatting. | + + +\anchor alltutorials +@} \ No newline at end of file diff --git a/tutorials/visualisation/graphs/zones.C b/tutorials/visualisation/graphs/zones.C deleted file mode 100644 index a167c0748f27c..0000000000000 --- a/tutorials/visualisation/graphs/zones.C +++ /dev/null @@ -1,39 +0,0 @@ -/// \file -/// \ingroup tutorial_graphs -/// \notebook -/// Example of script showing how to divide a canvas -/// into adjacent subpads + axis labels on the top and right side -/// of the pads. -/// -/// \macro_image -/// \macro_code -/// -/// \author Rene Brun - -void zones() -{ - TCanvas *c1 = new TCanvas("c1", "multipads", 900, 700); - gStyle->SetOptStat(0); - c1->Divide(2, 2, 0, 0); - TH2F *h1 = new TH2F("h1", "test1", 10, 0, 1, 20, 0, 20); - TH2F *h2 = new TH2F("h2", "test2", 10, 0, 1, 20, 0, 100); - TH2F *h3 = new TH2F("h3", "test3", 10, 0, 1, 20, -1, 1); - TH2F *h4 = new TH2F("h4", "test4", 10, 0, 1, 20, 0, 1000); - - c1->cd(1); - gPad->SetTickx(2); - h1->Draw(); - - c1->cd(2); - gPad->SetTickx(2); - gPad->SetTicky(2); - h2->GetYaxis()->SetLabelOffset(0.01); - h2->Draw(); - - c1->cd(3); - h3->Draw(); - - c1->cd(4); - gPad->SetTicky(2); - h4->Draw(); -} diff --git a/tutorials/visualisation/image/trans_graph.C b/tutorials/visualisation/image/trans_graph.C index 620587a7f79a8..91cda04352a90 100644 --- a/tutorials/visualisation/image/trans_graph.C +++ b/tutorials/visualisation/image/trans_graph.C @@ -34,8 +34,8 @@ void trans_graph() // switch to batch mode gROOT->SetBatch(kTRUE); - // execute graph.C macro - gROOT->Macro("$ROOTSYS/tutorials/visualisation/graphs/graph.C"); + // execute gr001_basic.C macro + gROOT->Macro("$ROOTSYS/tutorials/visualisation/graphs/gr001_basic.C"); // create gVirtualPS object TImageDump dmp("dummy.png");