Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
logscales.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_graphics
3/// \notebook
4/// \preview Draw parametric functions with log scales.
5///
6/// \macro_image
7/// \macro_code
8///
9/// \date July 2016
10/// \author Olivier Couet
11
12void logscales()
13{
14 TCanvas *c1 = new TCanvas("c1", "Various options on LOG scales plots", 0, 0, 700, 900);
15 c1->SetFillColor(30);
16
17 TPad *pad1 = new TPad("pad1", "pad1", 0.03, 0.62, 0.50, 0.92, 32);
18 TPad *pad2 = new TPad("pad2", "pad2", 0.51, 0.62, 0.98, 0.92, 33);
19 TPad *pad3 = new TPad("pad3", "pad3", 0.03, 0.02, 0.97, 0.535, 38);
20 pad1->Draw();
21 pad2->Draw();
22 pad3->Draw();
23
24 TPaveLabel *title = new TPaveLabel(0.1, 0.94, 0.9, 0.98, "Various options on LOG scales plots");
25 title->SetFillColor(16);
26 title->SetTextFont(42);
27 title->Draw();
28
29 TPaveText *pave = new TPaveText(0.1, 0.55, 0.9, 0.61);
30 pave->SetFillColor(42);
31 pave->SetTextAlign(12);
32 pave->SetTextFont(42);
33 pave->AddText("When more Log labels are requested, the overlapping labels are removed");
34 pave->Draw();
35
36 pad1->cd();
37 pad1->SetLogy();
38 pad1->SetGridy();
39 TF1 *f1 = new TF1("f1", "x*sin(x)*exp(-0.1*x)+15", -10., 10.);
40 TF1 *f2 = new TF1("f2", "(sin(x)+cos(x))**5+15", -10., 10.);
41 TF1 *f3 = new TF1("f3", "(sin(x)/(x)-x*cos(x))+15", -10., 10.);
42 f1->SetLineWidth(1);
43 f1->SetLineColor(2);
44 f2->SetLineWidth(1);
45 f2->SetLineColor(3);
46 f3->SetLineWidth(1);
47 f3->SetLineColor(4);
48 f1->Draw();
49 f2->Draw("same");
50 f3->Draw("same");
52 TPaveText *pave1 = new TPaveText(-6, 2, 6, 6);
53 pave1->SetFillColor(42);
54 pave1->SetTextAlign(12);
55 pave1->SetTextFont(42);
56 pave1->AddText("Log scale along Y axis.");
57 pave1->AddText("More Log labels requested.");
58 pave1->Draw();
59
60 pad2->cd();
61 double x[10] = {200, 300, 400, 500, 600, 650, 700, 710, 900, 1000};
62 double y[10] = {200, 1000, 900, 400, 500, 250, 800, 150, 201, 220};
63 TGraph *g_2 = new TGraph(10, x, y);
64 g_2->Draw("AL*");
65 g_2->SetMarkerColor(2);
66 g_2->GetYaxis()->SetMoreLogLabels();
67 g_2->GetYaxis()->SetNoExponent();
68 pad2->SetLogy();
69 g_2->GetXaxis()->SetMoreLogLabels();
70 pad2->SetLogx();
71 pad2->SetGridx();
72 TPaveText *pave2 = new TPaveText(150, 80, 500, 180);
73 pave2->SetFillColor(42);
74 pave2->SetTextFont(42);
75 pave2->SetTextAlign(12);
76 pave2->AddText("Log scale along X and Y axis.");
77 pave2->AddText("More Log labels on both.");
78 pave2->AddText("No exponent along Y axis.");
79 pave2->Draw();
80
81 pad3->cd();
82 pad3->SetGridx();
83 pad3->SetGridy();
84 pad3->SetLogy();
85 pad3->SetLogx();
86 TF1 *f4 = new TF1("f4a", "x*sin(x+10)+25", 1, 21);
87 f4->SetLineWidth(1);
88 f4->Draw();
89 f4->SetNpx(200);
92 f4 = new TF1("f4b", "x*cos(x+10)*sin(x+10)+25", 1, 21);
93 f4->SetLineWidth(1);
94 f4->Draw("same");
95 f4->SetNpx(200);
96 Int_t a = 20;
97 for (int i = a; i >= 1; i--) {
98 f4 = new TF1(Form("f4b_%d", i), "x*sin(x+10)*[0]/[1]+25", 1, 21);
99 f4->SetParameter(0, i);
100 f4->SetParameter(1, a);
101 f4->SetNpx(200);
102 f4->SetLineWidth(1);
103 f4->SetLineColor(i + 10);
104 f4->Draw("same");
105 f4 = new TF1(Form("f4c_%d", i), "x*cos(x+10)*sin(x+10)*[0]/[1]+25", 1, 25);
106 f4->SetParameter(0, i);
107 f4->SetParameter(1, a);
108 f4->SetNpx(200);
109 f4->SetLineWidth(1);
110 f4->SetLineColor(i + 30);
111 f4->Draw("same");
112 }
113 TPaveText *pave3 = new TPaveText(1.2, 8, 9, 15);
114 pave3->SetFillColor(42);
115 pave3->AddText("Log scale along X and Y axis.");
116 pave3->SetTextFont(42);
117 pave3->SetTextAlign(12);
118 pave3->AddText("More Log labels on both.");
119 pave3->AddText("The labels have no exponents (they would be 0 or 1)");
120 pave3->Draw();
121}
#define a(i)
Definition RSha256.hxx:99
int Int_t
Definition RtypesCore.h:45
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition TAttFill.h:38
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:45
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:42
virtual void SetTextFont(Font_t tfont=62)
Set the text font.
Definition TAttText.h:48
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:225
The Canvas class.
Definition TCanvas.h:23
1-Dim function class
Definition TF1.h:233
TAxis * GetYaxis() const
Get y axis of the function.
Definition TF1.cxx:2411
virtual void SetNpx(Int_t npx=100)
Set the number of points used to draw the function.
Definition TF1.cxx:3434
void Draw(Option_t *option="") override
Draw this function with its current attributes.
Definition TF1.cxx:1333
virtual void SetParameter(Int_t param, Double_t value)
Definition TF1.h:667
TAxis * GetXaxis() const
Get x axis of the function.
Definition TF1.cxx:2400
A TGraph is an object made of two arrays X and Y with npoints each.
Definition TGraph.h:41
The most important graphics class in the ROOT system.
Definition TPad.h:28
A Pave (see TPave) with a text centered in the Pave.
Definition TPaveLabel.h:20
void Draw(Option_t *option="") override
Draw this pavelabel with its current attributes.
A Pave (see TPave) with text, lines or/and boxes inside.
Definition TPaveText.h:21
Double_t y[n]
Definition legend1.C:17
return c1
Definition legend1.C:41
Double_t x[n]
Definition legend1.C:17
TF1 * f1
Definition legend1.C:11