Logo ROOT  
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
12void 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);
30 gr->Draw("AC*");
31
32 // Remove the frame's axis
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}
#define c(i)
Definition: RSha256.hxx:101
int Int_t
Definition: RtypesCore.h:41
double Double_t
Definition: RtypesCore.h:55
@ kRed
Definition: Rtypes.h:64
@ kWhite
Definition: Rtypes.h:63
#define gPad
Definition: TVirtualPad.h:286
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.
Definition: TAttAxis.cxx:204
virtual void SetTickLength(Float_t length=0.03)
Set tick mark length.
Definition: TAttAxis.cxx:280
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition: TAttText.h:42
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition: TAttText.h:46
The Canvas class.
Definition: TCanvas.h:31
The axis painter class.
Definition: TGaxis.h:24
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:2561
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void SetMaximum(Double_t maximum=-1111)
Set the maximum of the graph.
Definition: TGraph.cxx:2239
virtual void SetTitle(const char *title="")
Change (i.e.
Definition: TGraph.cxx:2312
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:753
TH1F * GetHistogram() const
Returns a pointer to the histogram used to draw the axis Takes into account the two following cases.
Definition: TGraph.cxx:1475
virtual void SetMinimum(Double_t minimum=-1111)
Set the minimum of the graph.
Definition: TGraph.cxx:2248
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:316
TAxis * GetYaxis()
Definition: TH1.h:317
To draw Mathematical Formula.
Definition: TLatex.h:18
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:195
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