TGraph, SetTitle, SetLog

Hi there,

Strange bug…
xtitle disappears whilst requesting logx (in either interpreted or compiled mode).
It depends on the number of lines in misc.txt.
If one removes the last line (line #18), everything’s fine.
The problem arises from version 5.24/00.
No prob with version 5.22/00.

Cheers,
Z

#include <TGraph.h> #include <TCanvas.h> #include <TPad.h> #include <TAxis.h> void ztemp () { TGraph *graph = new TGraph ("misc.txt","%lg %lg") ; graph->GetXaxis()->SetTitle("foo") ; TCanvas* canvas = new TCanvas ("canvas") ; printf ("\nxtitle = '%s'\n", graph->GetXaxis()->GetTitle()) ; gPad->SetLogx() ; printf ("\nxtitle = '%s'\n", graph->GetXaxis()->GetTitle()) ; return ; }
misc.txt (450 Bytes)

Like that it is ok:

void ztemp ()
{
   TCanvas* canvas = new TCanvas ("canvas") ;
   canvas->SetLogx() ;
   TGraph *graph = new TGraph ("misc.txt","%lg %lg") ;
   graph->GetXaxis()->SetTitle("foo") ;
   graph->Draw("AL");
}

gPad exist only if Draw has been perform.

Thanks Olivier.
In that case, this is only the “canvas->SetLogx()” statement that makes it not to work (from 5.24).

TGraph *graph = new TGraph ("misc.txt","%lg %lg") ; graph->GetXaxis()->SetTitle("foo") ; //TFile *fout = new TFile ("ztemp.root","recreate") ; //graph->Write() ; TCanvas* canvas = new TCanvas ("canvas") ; //canvas->SetLogx() ; graph->Draw("al") ;I don’t like the idea of mixing the “output print/plot” part and the “input/create data” part.
The TGraph object and its properties should be independent of it (everything can be saved in a TFile without any plotting).
For sure, I’m missing something (no prob in the past) but isn’t there any other way to deal with this?
TIA,
Z

I don’t understand the bug yet. I just came with something even simpler than your example which reproduces the problem:

void ztemp ()
{
   TCanvas* canvas = new TCanvas ("canvas") ;
   TGraph *graph = new TGraph ();
   graph->SetPoint(0, 0.00100, 30.00);      
   graph->SetPoint(1, 0.00155, 20.00);      
// Uncomment the next line and the axis title disappear.
//   graph->SetPoint(2, 0.01250, 10.00);    

   graph->Draw("AL*");
   graph->GetXaxis()->SetTitle("foo") ;
   gPad->SetLogx() ;   
}

I am still investigating

Hi Mathieu,
This bug is now fixed in the SVN trunk.
Sorry for the delay it was a tricky one.
Thanks to have seen it.
Cheers,
Olivier

Thanks for spending your time investigating! :wink:
Cheers,
Z