Logo ROOT  
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
11void graph()
12{
13 TCanvas *c1 = new TCanvas("c1", "A Simple Graph Example", 200, 10, 700, 500);
14
15 c1->SetGrid();
16
17 const Int_t n = 20;
18 Double_t x[n], y[n];
19 for (Int_t i = 0; i < n; i++) {
20 x[i] = i * 0.1;
21 y[i] = 10 * sin(x[i] + 0.2);
22 printf(" i %i %f %f \n", i, x[i], y[i]);
23 }
24 TGraph *gr = new TGraph(n, x, y);
25 gr->SetLineColor(2);
26 gr->SetLineWidth(4);
28 gr->SetMarkerStyle(21);
29 gr->SetTitle("a simple graph");
30 gr->GetXaxis()->SetTitle("X title");
31 gr->GetYaxis()->SetTitle("Y title");
32 gr->Draw("ACP");
33
34 // TCanvas::Update() draws the frame, after which one can change it
35 c1->Update();
36 c1->GetFrame()->SetBorderSize(12);
37 c1->Modified();
38}
int Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:38
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:40
The Canvas class.
Definition TCanvas.h:23
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
Definition TGraph.cxx:833
TAxis * GetXaxis() const
Get x axis of the graph.
Definition TGraph.cxx:1568
TAxis * GetYaxis() const
Get y axis of the graph.
Definition TGraph.cxx:1577
void SetTitle(const char *title="") override
Change (i.e.
Definition TGraph.cxx:2402
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
RVec< PromoteType< T > > sin(const RVec< T > &v)
Definition RVec.hxx:1851
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
TGraphErrors * gr
Definition legend1.C:25
Definition graph.py:1