Logarithmic scale and axis titles

Dears,
I have a problem to plot a graph using the log scale. In particular, the axis titles disappear when I set the log scale (if I remove the log scale they work properly).

Following the piece of code:

gPad.SetGrid()
canvas.SetTopMargin(.08)
canvas.SetRightMargin(0.05)
canvas.SetBottomMargin(0.13)
canvas.SetLeftMargin(0.16)

canvas.SetBorderSize(2)
canvas.SetFrameFillStyle(0);
canvas.SetFrameBorderMode(0);
canvas.SetFrameFillStyle(0);
canvas.SetFrameBorderMode(0);
 
canvas.Update()

gr = TGraph( "data.csv", "%lg %lg")	

gr.SetMarkerStyle(8)
gr.SetMarkerSize(1.6)
gr.SetMarkerColor(4)
gr.SetLineColor(4)
gr.Draw( 'AP' )


##############

canvas.Update()

gr.GetXaxis().SetTitle("X") 
gr.GetYaxis().SetTitle("Y")				
gr.GetXaxis().SetTitleFont(43)
gr.GetYaxis().SetTitleFont(43)	
gr.GetXaxis().SetTitleSize(25) 
gr.GetYaxis().SetTitleSize(25)						
gr.GetXaxis().SetTitleOffset(1) 
gr.GetYaxis().SetTitleOffset(1.4)						

gr.GetXaxis().SetLimits(0,5000) 				
gr.SetMinimum(0)
gr.SetMaximum(1000)	
						
gr.GetXaxis().SetLabelFont(43)
gr.GetYaxis().SetLabelFont(43)
gr.GetXaxis().SetLabelSize(22)
gr.GetYaxis().SetLabelSize(22)						
gr.GetXaxis().SetLabelOffset(0.005)
gr.GetYaxis().SetLabelOffset(.015)						
#gr.GetXaxis().SetNdivisions(20,5,0)


## Disable stats
ROOT.gROOT.SetBatch()
ROOT.gStyle.SetOptStat(0)
ROOT.gStyle.SetOptTitle(0)


canvas.SetLogx()
#canvas.SetLogy()

canvas.Update()

Where am I wrong?
thanks in advance :slight_smile:

Your program is not complete (for instance the data file is missing) therefore it cannot be run. Looking at it I do not see anything wrong.
I ran $ROOTSYS/tutorials/graphs/graph.C. It has axis axis titles. Turning log scale on for X or/and Y axis does not drop the titles.

Dear Couet,
thanks for the reply. Followig the complete code, and also the data:

# -*- coding: utf-8 -*-					

import ROOT
from ROOT import gROOT
from ROOT import TCanvas, TGraph, gPad, TF1, TF2 , kRed, TMultiGraph, TLegend, gStyle, TPaveStats, TStyle, TText, TList, TLatex, TMath, TFormula, TGraphErrors, TCanvas, TGraph, gPad, TF1, kRed, TMultiGraph, TLegend, gStyle, TPaveStats, TStyle, TText, TList, TLatex, TMultiGraph, kViolet, kMagenta, kBlue, kAzure,kCyan, kGreen, kTeal, kSpring, TLine
import string										



canvas = TCanvas("canvas","canvas", 600, 600)			

gPad.SetGrid()

canvas.SetTopMargin(.08)
canvas.SetRightMargin(0.05)
canvas.SetBottomMargin(0.13)
canvas.SetLeftMargin(0.16)

canvas.SetBorderSize(2)
canvas.SetFrameFillStyle(0);
canvas.SetFrameBorderMode(0);
canvas.SetFrameFillStyle(0);
canvas.SetFrameBorderMode(0);
  

canvas.SetLogx()
#canvas.SetLogy()

canvas.Update()
canvas.Modified()


gr = TGraph( "data.csv", "%lg %lg")	

gr.SetMarkerStyle(8)
gr.SetMarkerSize(1.6)
gr.SetMarkerColor(4)
gr.SetLineColor(4)
gr.Draw( 'AP' )


##############

canvas.Update()

gr.GetXaxis().SetTitle("X") 
gr.GetYaxis().SetTitle("Y")				
gr.GetXaxis().SetTitleFont(43)
gr.GetYaxis().SetTitleFont(43)	
gr.GetXaxis().SetTitleSize(25) 
gr.GetYaxis().SetTitleSize(25)						
gr.GetXaxis().SetTitleOffset(1) 
gr.GetYaxis().SetTitleOffset(1.4)						
gr.GetXaxis().SetLimits(0,5000) 				
gr.SetMinimum(0)
gr.SetMaximum(1000)							

gr.GetXaxis().SetLabelFont(43)
gr.GetYaxis().SetLabelFont(43)
gr.GetXaxis().SetLabelSize(22)
gr.GetYaxis().SetLabelSize(22)						
gr.GetXaxis().SetLabelOffset(0.005)
gr.GetYaxis().SetLabelOffset(.015)						



## Disable stats
ROOT.gROOT.SetBatch()
ROOT.gStyle.SetOptStat(0)
ROOT.gStyle.SetOptTitle(0)



canvas.Update()


name_plot_png= "try.png"	
canvas.SaveAs(name_plot_png)
####   DATA

10	889
30	881
50	880
70	884
80	880
90	871
100	871
200	820
500	653
1000	628
1500	459
2000	412
5000	382

I did a comparison witht the example but I didn’t found anything strange…
Thanks a lot in advance :slight_smile:

gr.GetXaxis().SetLimits(0,5000)

Is invalid when you have log along X … (0 is not valid in log scale…) … change it to a positive value and the title will show.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.