Logo ROOT  
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
16import numpy as np
17import ROOT
18
19npoints = 3
20xaxis = np.array([1.0, 2.0, 3.0])
21yaxis = np.array([10.0, 20.0, 30.0])
22
23gr1 = ROOT.TGraph(npoints, xaxis, yaxis)
24ff = ROOT.TF2("ff", "-1./y") # Defining the function `f`
25
26c1 = ROOT.TCanvas("c1", "c1", 0, 0, 700, 500)
27c1.Divide(2, 1)
28
29c1.cd(1)
30gr1.DrawClone("A*") # Using DrawClone to create a copy of the graph in the canvas.
31c1.cd(2)
32gr1.Apply(ff) # Applies the function `f` to all the data TGraph points
33gr1.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).
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.