Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 }