Logo ROOT   6.10/09
Reference Guide
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);
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 }
void SetFrameLineColor(Color_t color=1)
Definition: TAttPad.h:74
Definition: Rtypes.h:56
void SetFrameBorderMode(Int_t mode=1)
Definition: TAttPad.h:79
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum of the graph.
Definition: TGraph.cxx:2147
int Int_t
Definition: RtypesCore.h:41
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:202
virtual void SetTitle(const char *title="")
Set graph title.
Definition: TGraph.cxx:2180
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:745
Double_t x[n]
Definition: legend1.C:17
To draw Mathematical Formula.
Definition: TLatex.h:18
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum of the graph.
Definition: TGraph.cxx:2138
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
Definition: Rtypes.h:55
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition: TAttText.h:42
The axis painter class.
Definition: TGaxis.h:24
TAxis * GetYaxis()
Definition: TH1.h:301
virtual void SetAxisColor(Color_t color=1, Float_t alpha=1.)
Set color of the line axis and tick marks.
Definition: TAttAxis.cxx:163
virtual void SetLabelSize(Float_t size=0.04)
Set size of axis labels The size is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:204
TGraphErrors * gr
Definition: legend1.C:25
The Canvas class.
Definition: TCanvas.h:31
TH1F * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases...
Definition: TGraph.cxx:1469
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:41
#define gPad
Definition: TVirtualPad.h:284
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length The length is expressed in per cent of the pad width.
Definition: TAttAxis.cxx:249
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
const Int_t n
Definition: legend1.C:16
TAxis * GetXaxis()
Definition: TH1.h:300
void ChangeLabel(Int_t labNum=0, Double_t labAngle=-1., Double_t labSize=-1., Int_t labAlign=-1, Int_t labColor=-1, Int_t labFont=-1, TString labText="")
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2333