ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
graph.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_graphs
3
/// \notebook
4
/// Draw a simple graph.
5
///
6
/// \macro_image
7
/// \macro_code
8
///
9
/// \author Rene Brun
10
11
void
graph
() {
12
TCanvas
*
c1
=
new
TCanvas
(
"c1"
,
"A Simple Graph Example"
,200,10,700,500);
13
14
c1
->SetGrid();
15
16
const
Int_t
n
= 20;
17
Double_t
x
[
n
],
y
[
n
];
18
for
(
Int_t
i
=0;
i
<
n
;
i
++) {
19
x
[
i
] =
i
*0.1;
20
y
[
i
] = 10*
sin
(
x
[
i
]+0.2);
21
printf(
" i %i %f %f \n"
,
i
,
x
[
i
],
y
[
i
]);
22
}
23
TGraph
*
gr
=
new
TGraph
(
n
,
x
,
y
);
24
gr
->SetLineColor(2);
25
gr
->SetLineWidth(4);
26
gr
->SetMarkerColor(4);
27
gr
->SetMarkerStyle(21);
28
gr
->SetTitle(
"a simple graph"
);
29
gr
->GetXaxis()->SetTitle(
"X title"
);
30
gr
->GetYaxis()->SetTitle(
"Y title"
);
31
gr
->Draw(
"ACP"
);
32
33
// TCanvas::Update() draws the frame, after which one can change it
34
c1
->Update();
35
c1
->GetFrame()->SetBorderSize(12);
36
c1
->Modified();
37
}
Int_t
int Int_t
Definition
RtypesCore.h:45
Double_t
double Double_t
Definition
RtypesCore.h:59
i
Int_t i
Definition
TGraphAsymmErrors.cxx:1306
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition
TGraph.h:41
ROOT::VecOps::sin
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition
RVec.hxx:1852
y
Double_t y[n]
Definition
legend1.C:17
c1
return c1
Definition
legend1.C:41
x
Double_t x[n]
Definition
legend1.C:17
n
const Int_t n
Definition
legend1.C:16
gr
TGraphErrors * gr
Definition
legend1.C:25
graph
Definition
graph.py:1
tutorials
graphs
graph.C
ROOT v6-32 - Reference Guide Generated on Tue May 19 2026 02:47:09 (GVA Time) using Doxygen 1.13.2