Logo ROOT   6.18/05
Reference Guide
logscales.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_hist
3/// \notebook
4/// Draw parametric functions with log scales.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \author Olivier Couet
10
11void logscales() {
12 TCanvas *c1 = new TCanvas("c1", "Various options on LOG scales plots",0,0,700,900);
13 c1->SetFillColor(30);
14
15 TPad *pad1 = new TPad("pad1","pad1",0.03,0.62,0.50,0.92,32);
16 TPad *pad2 = new TPad("pad2","pad2",0.51,0.62,0.98,0.92,33);
17 TPad *pad3 = new TPad("pad3","pad3",0.03,0.02,0.97,0.535,38);
18 pad1->Draw(); pad2->Draw(); pad3->Draw();
19
20 TPaveLabel *title = new TPaveLabel(0.1,0.94,0.9,0.98, "Various options on LOG scales plots");
21 title->SetFillColor(16);
22 title->SetTextFont(42);
23 title->Draw();
24
25 TPaveText *pave = new TPaveText(0.1,0.55,0.9,0.61);
26 pave->SetFillColor(42);
27 pave->SetTextAlign(12);
28 pave->SetTextFont(42);
29 pave->AddText("When more Log labels are requested, the overlapping labels are removed");
30 pave->Draw();
31
32 pad1->cd();
33 pad1->SetLogy();
34 pad1->SetGridy();
35 TF1 *f1 = new TF1("f1","x*sin(x)*exp(-0.1*x)+15",-10.,10.);
36 TF1 *f2 = new TF1("f2","(sin(x)+cos(x))**5+15",-10.,10.);
37 TF1 *f3 = new TF1("f3","(sin(x)/(x)-x*cos(x))+15",-10.,10.);
39 f2->SetLineWidth(1); f2->SetLineColor(3);
40 f3->SetLineWidth(1); f3->SetLineColor(4);
41 f1->Draw();
42 f2->Draw("same");
43 f3->Draw("same");
45 TPaveText *pave1 = new TPaveText(-6,2,6,6);
46 pave1->SetFillColor(42);
47 pave1->SetTextAlign(12);
48 pave1->SetTextFont(42);
49 pave1->AddText("Log scale along Y axis.");
50 pave1->AddText("More Log labels requested.");
51 pave1->Draw();
52
53 pad2->cd();
54 double x[10] = { 200, 300, 400, 500, 600, 650, 700, 710, 900,1000 };
55 double y[10] = { 200, 1000, 900, 400, 500, 250, 800, 150, 201, 220 };
56 TGraph *g_2 = new TGraph(10,x,y);
57 g_2->Draw("AL*");
58 g_2->SetMarkerColor(2);
59 g_2->GetYaxis()->SetMoreLogLabels();
60 g_2->GetYaxis()->SetNoExponent();
61 pad2->SetLogy();
62 g_2->GetXaxis()->SetMoreLogLabels();
63 pad2->SetLogx();
64 pad2->SetGridx();
65 TPaveText *pave2 = new TPaveText(150,80,500,180);
66 pave2->SetFillColor(42);
67 pave2->SetTextFont(42);
68 pave2->SetTextAlign(12);
69 pave2->AddText("Log scale along X and Y axis.");
70 pave2->AddText("More Log labels on both.");
71 pave2->AddText("No exponent along Y axis.");
72 pave2->Draw();
73
74 pad3->cd();
75 pad3->SetGridx();
76 pad3->SetGridy();
77 pad3->SetLogy();
78 pad3->SetLogx();
79 TF1 *f4 = new TF1("f4a","x*sin(x+10)+25",1,21);
80 f4->SetLineWidth(1);
81 f4->Draw();
82 f4->SetNpx(200);
85 f4 = new TF1("f4b","x*cos(x+10)*sin(x+10)+25",1,21);
86 f4->SetLineWidth(1); f4->Draw("same");
87 f4->SetNpx(200);
88 Int_t a = 20;
89 for (int i=a; i>=1; i--) {
90 f4 = new TF1(Form("f4b_%d",i),"x*sin(x+10)*[0]/[1]+25",1,21);
91 f4->SetParameter(0,i);
92 f4->SetParameter(1,a);
93 f4->SetNpx(200);
94 f4->SetLineWidth(1); f4->SetLineColor(i+10);
95 f4->Draw("same");
96 f4 = new TF1(Form("f4c_%d",i),"x*cos(x+10)*sin(x+10)*[0]/[1]+25",1,25);
97 f4->SetParameter(0,i);
98 f4->SetParameter(1,a);
99 f4->SetNpx(200);
100 f4->SetLineWidth(1); f4->SetLineColor(i+30); f4->Draw("same");
101 }
102 TPaveText *pave3 = new TPaveText(1.2,8,9,15);
103 pave3->SetFillColor(42);
104 pave3->AddText("Log scale along X and Y axis.");
105 pave3->SetTextFont(42);
106 pave3->SetTextAlign(12);
107 pave3->AddText("More Log labels on both.");
108 pave3->AddText("The labels have no exponents (they would be 0 or 1)");
109 pave3->Draw();
110}
int Int_t
Definition: RtypesCore.h:41
char * Form(const char *fmt,...)
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:37
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition: TAttLine.h:43
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition: TAttMarker.h:38
virtual void SetTextAlign(Short_t align=11)
Set the text alignment.
Definition: TAttText.h:41
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition: TAttText.h:45
void SetMoreLogLabels(Bool_t more=kTRUE)
Set the kMoreLogLabels bit flag When this option is selected more labels are drawn when in log scale ...
Definition: TAxis.h:213
void SetNoExponent(Bool_t noExponent=kTRUE)
Set the NoExponent flag By default, an exponent of the form 10^N is used when the label value are eit...
Definition: TAxis.h:223
The Canvas class.
Definition: TCanvas.h:31
1-Dim function class
Definition: TF1.h:211
TAxis * GetYaxis() const
Get y axis of the function.
Definition: TF1.cxx:2393
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition: TF1.cxx:3432
virtual void Draw(Option_t *option="")
Draw this function with its current attributes.
Definition: TF1.cxx:1317
virtual void SetParameter(Int_t param, Double_t value)
Definition: TF1.h:628
TAxis * GetXaxis() const
Get x axis of the function.
Definition: TF1.cxx:2382
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
virtual void Draw(Option_t *chopt="")
Draw this graph with its current attributes.
Definition: TGraph.cxx:747
TAxis * GetXaxis() const
Get x axis of the graph.
Definition: TGraph.cxx:1592
TAxis * GetYaxis() const
Get y axis of the graph.
Definition: TGraph.cxx:1602
The most important graphics class in the ROOT system.
Definition: TPad.h:29
virtual void SetLogy(Int_t value=1)
Set Lin/Log scale for Y.
Definition: TPad.cxx:5856
virtual void SetGridx(Int_t value=1)
Definition: TPad.h:329
virtual void SetGridy(Int_t value=1)
Definition: TPad.h:330
virtual void SetLogx(Int_t value=1)
Set Lin/Log scale for X.
Definition: TPad.cxx:5842
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
A Pave (see TPave) with a text centered in the Pave.
Definition: TPaveLabel.h:20
virtual void Draw(Option_t *option="")
Draw this pavelabel with its current attributes.
Definition: TPaveLabel.cxx:77
A Pave (see TPave) with text, lines or/and boxes inside.
Definition: TPaveText.h:21
virtual TText * AddText(Double_t x1, Double_t y1, const char *label)
Add a new Text line to this pavetext at given coordinates.
Definition: TPaveText.cxx:182
virtual void Draw(Option_t *option="")
Draw this pavetext with its current attributes.
Definition: TPaveText.cxx:233
return c1
Definition: legend1.C:41
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
TF1 * f1
Definition: legend1.C:11
auto * a
Definition: textangle.C:12