ROOT
v6-36
Reference Guide
Loading...
Searching...
No Matches
gr005_apply.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_graphs
3
## \notebook
4
## \preview A macro to demonstrate the functionality of TGraph::Apply() method.
5
## 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.
6
## The Y values of the graph are replaced by the ROOT.values computed using the function.
7
##
8
##
9
## The Apply() method can be used as well for TGraphErrors and TGraphAsymmErrors.
10
##
11
## \macro_image
12
## \macro_code
13
##
14
## \author Miro Helbich, Jamie Gooding
15
16
import
numpy
as
np
17
import
ROOT
18
19
npoints = 3
20
xaxis =
np.array
([1.0, 2.0, 3.0])
21
yaxis =
np.array
([10.0, 20.0, 30.0])
22
23
gr1 =
ROOT.TGraph
(npoints, xaxis, yaxis)
24
ff =
ROOT.TF2
(
"ff"
,
"-1./y"
)
# Defining the function `f`
25
26
c1 =
ROOT.TCanvas
(
"c1"
,
"c1"
, 0, 0, 700, 500)
27
c1.Divide
(2, 1)
28
29
c1.cd
(1)
30
gr1.DrawClone
(
"A*"
)
# Using DrawClone to create a copy of the graph in the canvas.
31
c1.cd
(2)
32
gr1.Apply
(ff)
# Applies the function `f` to all the data TGraph points
33
gr1.Draw
(
"A*"
)
34
# Without DrawClone, the modifications to gr1 via Apply(ff) are reflected in the original graph
35
# displayed in c1 (the two drawn graphs are not independent).
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
tutorials
visualisation
graphs
gr005_apply.py
ROOT v6-36 - Reference Guide Generated on Thu Aug 21 2025 04:30:48 (GVA Time) using Doxygen 1.10.0