Logo ROOT   6.08/07
Reference Guide
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 }
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:49
return c1
Definition: legend1.C:41
TAxis * GetYaxis() const
Get y axis of the graph.
Definition: TGraph.cxx:1596
int Int_t
Definition: RtypesCore.h:41
virtual void SetTitle(const char *title="")
Set graph title.
Definition: TGraph.cxx:2176
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:747
Double_t x[n]
Definition: legend1.C:17
TFrame * GetFrame()
Get frame.
Definition: TPad.cxx:2746
virtual void SetGrid(Int_t valuex=1, Int_t valuey=1)
Definition: TPad.h:318
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:43
double sin(double)
virtual void SetBorderSize(Short_t bordersize)
Definition: TWbox.h:54
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:46
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition: TAttMarker.h:45
Definition: graph.py:1
TGraphErrors * gr
Definition: legend1.C:25
TAxis * GetXaxis() const
Get x axis of the graph.
Definition: TGraph.cxx:1586
The Canvas class.
Definition: TCanvas.h:41
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2183
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
const Int_t n
Definition: legend1.C:16
void Modified(Bool_t flag=1)
Definition: TPad.h:399