Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
xyplot.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// \preview 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/// \date January 2017
11/// \author Olivier Couet
12
13void xyplot()
14{
15 TCanvas *c = new TCanvas("c", "XY plot", 200, 10, 700, 500);
16
17 // Remove the frame
18 c->SetFillColor(kWhite);
19 c->SetFrameLineColor(kWhite);
20 c->SetFrameBorderMode(0);
21
22 // Define and draw a curve the frame
23 const Int_t n = 4;
24 Double_t x[n] = {-1, -3, -9, 3};
25 Double_t y[n] = {-1000, 900, 300, 300};
26 TGraph *gr = new TGraph(n, x, y);
27 gr->SetTitle("XY plot");
28 gr->SetMinimum(-1080);
29 gr->SetMaximum(1080);
30 gr->SetLineColor(kRed);
31 gr->Draw("AC*");
32
33 // Remove the frame's axis
34 gr->GetHistogram()->GetYaxis()->SetTickLength(0);
35 gr->GetHistogram()->GetXaxis()->SetTickLength(0);
36 gr->GetHistogram()->GetYaxis()->SetLabelSize(0);
37 gr->GetHistogram()->GetXaxis()->SetLabelSize(0);
38 gr->GetHistogram()->GetXaxis()->SetAxisColor(0);
39 gr->GetHistogram()->GetYaxis()->SetAxisColor(0);
40
41 gPad->Update();
42
43 // Draw orthogonal axis system centered at (0,0).
44 // Draw the Y axis. Note the 4th label is erased with SetLabelAttributes
45 TGaxis *yaxis = new TGaxis(0, gPad->GetUymin(), 0, gPad->GetUymax(), gPad->GetUymin(), gPad->GetUymax(), 6, "+LN");
46 yaxis->ChangeLabel(4, -1, 0.);
47 yaxis->Draw();
48
49 // Draw the Y-axis title.
50 TLatex *ytitle = new TLatex(-0.5, gPad->GetUymax(), "Y axis");
51 ytitle->Draw();
52 ytitle->SetTextSize(0.03);
53 ytitle->SetTextAngle(90.);
54 ytitle->SetTextAlign(31);
55
56 // Draw the X axis
57 TGaxis *xaxis = new TGaxis(gPad->GetUxmin(), 0, gPad->GetUxmax(), 0, gPad->GetUxmin(), gPad->GetUxmax(), 510, "+L");
58 xaxis->Draw();
59
60 // Draw the X axis title.
61 TLatex *xtitle = new TLatex(gPad->GetUxmax(), -200., "X axis");
62 xtitle->Draw();
63 xtitle->SetTextAlign(31);
64 xtitle->SetTextSize(0.03);
65}
#define c(i)
Definition RSha256.hxx:101
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
@ kRed
Definition Rtypes.h:67
@ kWhite
Definition Rtypes.h:66
#define gPad
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition TAttText.h:48
virtual void SetTextAngle(Float_t tangle=0)
Set the text angle.
Definition TAttText.h:49
virtual void SetTextSize(Float_t tsize=1)
Set the text size.
Definition TAttText.h:53
The Canvas class.
Definition TCanvas.h:23
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, const TString &labText="")
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition TObject.cxx:293
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