Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
xyplot.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_hist
3 /// \notebook
4 /// Example showing how to produce a plot with an orthogonal axis system
5 /// centered at (0,0).
6 ///
7 /// \macro_image
8 /// \macro_code
9 ///
10 /// \author Olivier Couet
11 
12 void xyplot()
13 {
14  TCanvas *c = new TCanvas("c","XY plot",200,10,700,500);
15 
16  // Remove the frame
17  c->SetFillColor(kWhite);
18  c->SetFrameLineColor(kWhite);
19  c->SetFrameBorderMode(0);
20 
21  // Define and draw a curve the frame
22  const Int_t n = 4;
23  Double_t x[n] = {-1, -3, -9, 3};
24  Double_t y[n] = {-1000, 900, 300, 300};
25  TGraph* gr = new TGraph(n,x,y);
26  gr->SetTitle("XY plot");
27  gr->SetMinimum(-1080);
28  gr->SetMaximum(1080);
29  gr->SetLineColor(kRed);
30  gr->Draw("AC*");
31 
32  // Remove the frame's axis
33  gr->GetHistogram()->GetYaxis()->SetTickLength(0);
34  gr->GetHistogram()->GetXaxis()->SetTickLength(0);
35  gr->GetHistogram()->GetYaxis()->SetLabelSize(0);
36  gr->GetHistogram()->GetXaxis()->SetLabelSize(0);
37  gr->GetHistogram()->GetXaxis()->SetAxisColor(0);
38  gr->GetHistogram()->GetYaxis()->SetAxisColor(0);
39 
40  gPad->Update();
41 
42  // Draw orthogonal axis system centered at (0,0).
43  // Draw the Y axis. Note the 4th label is erased with SetLabelAttributes
44  TGaxis *yaxis = new TGaxis(0, gPad->GetUymin(),
45  0, gPad->GetUymax(),
46  gPad->GetUymin(),gPad->GetUymax(),6,"+LN");
47  yaxis->ChangeLabel(4,-1,0.);
48  yaxis->Draw();
49 
50  // Draw the Y-axis title.
51  TLatex *ytitle = new TLatex(-0.5,gPad->GetUymax(),"Y axis");
52  ytitle->Draw();
53  ytitle->SetTextSize(0.03);
54  ytitle->SetTextAngle(90.);
55  ytitle->SetTextAlign(31);
56 
57  // Draw the X axis
58  TGaxis *xaxis = new TGaxis(gPad->GetUxmin(), 0,
59  gPad->GetUxmax(), 0,
60  gPad->GetUxmin(),gPad->GetUxmax(),510,"+L");
61  xaxis->Draw();
62 
63  // Draw the X axis title.
64  TLatex *xtitle = new TLatex(gPad->GetUxmax(),-200.,"X axis");
65  xtitle->Draw();
66  xtitle->SetTextAlign(31);
67  xtitle->SetTextSize(0.03);
68 }