Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
gr110_logscale.C File Reference

Detailed Description

View in nbviewer Open in SWAN
This tutorial demonstrates how to set a logarithmic scale for the axes of a graph using the SetLogScale() method.

The logarithmic scale can be applied to either the x-axis, the y-axis, or both axes at the same time. When using a logarithmic scale, the data must be positive since the logarithm is undefined for non-positive values and zero.

¸o␟W␎

void gr110_logscale() {
auto c = new TCanvas("c","Reversed graphs",0,0,900,400);
c->Divide(2,1);
c->cd(1);
const Int_t n = 6; //Fill the arrays x and y with the data points
Double_t x[n], y[n];
for (Int_t i=0;i<n;i++) {
x[i] = i+1;
y[i] = exp(i+1);
}
TGraph *gr1 = new TGraph(n,x,y);
gr1->SetLineColor(2);
gr1->SetLineWidth(4);
gr1->SetMarkerColor(4);
gr1->SetMarkerStyle(21);
gr1->SetTitle("Graph without log scale");
gr1->DrawClone("ACP");
//The logarithmic scale setting can also be done in a ROOT interactive session.
c->cd(2);
gPad->SetLogy();
//gPad->SetLogx(); Uncomment this line if log scale is needed on both axes
gr1->SetTitle("Graph with y log scale");
gr1->Draw("ACP");
}
#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
#define gPad
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
Definition TAttLine.h:47
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition TAttLine.h:44
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
Definition TAttMarker.h:41
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition TAttMarker.h:43
The Canvas class.
Definition TCanvas.h:23
void Draw(Option_t *chopt="") override
Default Draw method for all objects.
void SetTitle(const char *title="") override
Set the title of the TNamed.
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad with: gROOT->SetSelectedPad(c1).
Definition TObject.cxx:319
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Date
25/11/2024
Author
Emanuele Chiamulera

Definition in file gr110_logscale.C.