Log scale in TGraphErrors

Hello

How can one draw a TGraphErrors object with a logarithmic y-axis? SetLogy doesn’t work, because it isn’t a member of TGraphErrors, and using SetLogy on the canvas object does nothing at all that I can see.

Thanks.

Setting the canvas’ y-axis to logscale should work. Can you post a minimal example of what you try to do?

#include <math.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <fstream>
#include <new>
#include <pthread.h>
#include <unistd.h>
#include <string>
#include <sys/stat.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TFile.h>
#include <TCanvas.h>
#include <TGraphErrors.h>
#include <TTree.h>
#include <TH1.h>
#include <TH2.h>
#include <TF1.h>
#include <TLine.h>
#include <TSocket.h>
#include <TFrame.h>
#include <TText.h>
#include <TStyle.h>
#include <TLegend.h>

#include <ctype.h>
using namespace std;


int main(int argc, char* argv[])
{
  int nlc=4;



  TCanvas* LCCanvas = new TCanvas("LCCanvas","LCCanvas", 0, 0, 1200, 800);
  LCCanvas->SetFillColor(kWhite);
  LCCanvas->SetLogy();
  LCCanvas->Divide(1,nlc,1e-17,1e-17); 

  Double_t lc_x1[]={1,2,3,4,5};
  Double_t lc_x1_errors[]={0.1,0.1,0.1,0.1,0.1};
  Double_t lc_y1[]={1,10,100,1000,10000};
  Double_t lc_y1_errors[]={0.1,1,10,100,1000};



      //For waveform one
  for (int m=0;m<nlc;m++) {
    TGraphErrors* LCGraph = new TGraphErrors(5, lc_x1, lc_y1,lc_x1_errors, lc_y1_errors);
    LCGraph->SetMarkerColor(kBlack);
    LCGraph->SetMarkerStyle(1);
    LCGraph->GetXaxis()->SetTitle("MJD");
    LCGraph->GetXaxis()->CenterTitle(1);
    LCGraph->GetXaxis()->SetRangeUser(0, 50);
    LCGraph->GetYaxis()->CenterTitle(1);
    LCGraph->GetYaxis()->SetTitleOffset(1.35);
    LCGraph->GetYaxis()->SetLabelSize(0.032);
    LCCanvas->SetLogy();
    LCCanvas->cd(m+1);

    LCGraph->Draw("APZ");
    
  }
  
  LCCanvas->Print("test1.ps");
  return 0;
  
}

It doesn’t do any sort of log scale on the y axis even though I tell it to do so twice. Any help would be appreciated. Thanks.

Hi msj,

You are setting the canvas to logscale, but since you divided that canvas you
don’t draw anything directly in there – you do draw into the contained pads.
You should set the current pads to logscale instead. The current pad is
returned by TCanvas::cd, so you could either call

    LCCanvas->cd(m+1)->SetLogy();

or perhaps more clearly via the gPad global

gPad->SetLogy();

instead of working on the canvas.

If you hadn’t divided the canvas it would have been the current pad and things would have worked like you probably expected.

Thank you so much for the help. I was trying to figure this out for days.