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 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);
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 Int_t
Definition RtypesCore.h:45
double Double_t
Definition RtypesCore.h:59
double sin(double)
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
virtual void SetTitle(const char *title="")
Change (i.e.
Definition TGraph.cxx:2339
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition TGraph.cxx:769
TAxis * GetXaxis() const
Get x axis of the graph.
Definition TGraph.cxx:1640
TAxis * GetYaxis() const
Get y axis of the graph.
Definition TGraph.cxx:1650
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition TNamed.cxx:164
return c1
Definition legend1.C:41
Double_t y[n]
Definition legend1.C:17
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