# Logarithmic Scale

How does one change the scale in logarithmic for a TGraph or TH1?

Once you have done a plot (TGraph or Histogram). Just Do:

``gPad->SetLogx();``

To come back to linear:

``gPad->SetLogx(0);``

You can also use the context menu on the Canvas.

Thanks.
Supposing however I want to Draw(“AL same”), ie overplot? If i call the function again, the old pad is erased…

Overplot with graphs is only Draw("L) … read the doc.

``````TGraph *readData (char *fname, const int line) {
TCanvas *c1=new TCanvas(); // this is needed by gPad, however this erases old canvas and creates a new one.  What I aim to do is overplot by calling several fnames
float rate,contrast;
TGraph *g= new TGraph();
FILE *fp = fopen(fname,"r");
if(fp==NULL) {
printf("Could nor open file %s\n", fname);
return g;
}

for(int iline=0; iline<line; iline++) {
fscanf(fp,"%f %f\n", &rate, &contrast);
g->SetPoint(iline, rate/1000., contrast);
}
fclose(fp);
return g;
}``````
``   TCanvas *c1=new TCanvas(); // this is needed by gPad, however this erases old canvas and creates a new one.  What I aim to do is overplot by calling several fnames``

Create your canvas outside this function. The way it is written now, each time you will call it, it will make a new canvas. If you need to cumulate graphs on the same plot you can :

1. plot Draw the first graph using “AL” and the next graph using “L”. read the doc… root.cern.ch/root/html/TGraphPainter.html

or

Thanks!