ROOT
Version master
master
v6.34
v6.32
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
v6.04
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
gr110_logscale.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_graphs
3
/// \notebook
4
/// \preview This tutorial demonstrates how to set a logarithmic scale for the axes of a graph using the `SetLogScale()` method.
5
/// The logarithmic scale can be applied to either the x-axis, the y-axis, or both axes at the same time.
6
/// When using a logarithmic scale, the data must be positive since the logarithm is undefined for non-positive values and zero.
7
///
8
/// \macro_image
9
/// \macro_code
10
/// \date 25/11/2024
11
/// \author Emanuele Chiamulera
12
13
void
gr110_logscale
() {
14
15
auto
c
=
new
TCanvas
(
"c"
,
"Reversed graphs"
,0,0,900,400);
16
c
->Divide(2,1);
17
c
->cd(1);
18
19
const
Int_t
n
= 6;
//Fill the arrays x and y with the data points
20
Double_t
x
[
n
],
y
[
n
];
21
for
(
Int_t
i=0;i<
n
;i++) {
22
x
[i] = i+1;
23
y
[i] = exp(i+1);
24
}
25
26
TGraph
*
gr1
=
new
TGraph
(
n
,
x
,
y
);
27
28
gr1
->SetLineColor(2);
29
gr1
->SetLineWidth(4);
30
gr1
->SetMarkerColor(4);
31
gr1
->SetMarkerStyle(21);
32
gr1
->SetTitle(
"Graph without log scale"
);
33
gr1
->DrawClone(
"ACP"
);
34
35
//The logarithmic scale setting can also be done in a ROOT interactive session.
36
c
->cd(2);
37
gPad
->SetLogy();
38
//gPad->SetLogx(); Uncomment this line if log scale is needed on both axes
39
gr1
->SetTitle(
"Graph with y log scale"
);
40
gr1
->Draw(
"ACP"
);
41
42
}
c
#define c(i)
Definition
RSha256.hxx:101
Int_t
int Int_t
Definition
RtypesCore.h:45
Double_t
double Double_t
Definition
RtypesCore.h:59
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
gPad
#define gPad
Definition
TVirtualPad.h:308
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition
TGraph.h:41
y
Double_t y[n]
Definition
legend1.C:17
x
Double_t x[n]
Definition
legend1.C:17
n
const Int_t n
Definition
legend1.C:16
tutorials
visualisation
graphs
gr110_logscale.C
ROOT master - Reference Guide Generated on Mon Feb 24 2025 14:45:13 (GVA Time) using Doxygen 1.10.0