Showing TGraph axis title in TBrowser

Hi everybody,

I want to save TGraph objects together with their axis titles in a root file such that when opened with TBrowser the axis titles are shown. When I write the TGraph objects to a root file after setting the axis titles the axis titles disappear when the TGraph objects are viewed in the TBrowser. I have found similar topics discussing this subject but they all do not give a clear solution to my problem.

Thank you in advance.

With kind regards

Could you perhaps show your code?

What I sometimes do is save the canvas on which the graph is, in that case I don’t have problems with viewing the titles in the TBrowser. I don’t remember if I ever tried just saving the graph and having problems with viewing the titles in a TBrowser.

Cheers

Nikkie

I juste tried with the master on Mac. It is fine.

I used the following macro to create the graph and save it in a root file:

void graph() {
   TCanvas *c = new TCanvas("c","A Simple Graph without axis",700,500);
   c->Range(-0.1,0.,1.,10.);

   const Int_t n = 10;
   TGraph *gr = new TGraph(n);
   gr->SetTitle("A Simple Graph Example");
   gr->GetXaxis()->SetTitle("X axis");
   gr->SetMarkerStyle(20);

   Double_t x, y;
   for (Int_t i=0;i<n;i++) {
      x = i*0.1;
      y = 10*sin(x+0.2);
      gr->SetPoint(i,x,y);

   }

   gr->Draw("ALP");
   TFile *f = new TFile("g.root","RECREATE");
   gr->Write();
 }

Then I exit root and re-start it with:

$ root g.root 
   -----------------------------------------------------------------
  | Welcome to ROOT 6.11/01                     http://root.cern.ch |
  |                                    (c) 1995-2017, The ROOT Team |
  | Built for macosx64                                              |
  | From heads/master@v6-09-02-2286-g182a914, Sep 04 2017, 14:33:42 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'      |
   -----------------------------------------------------------------

root [0] 
Attaching file g.root as _file0...
(TFile *) 0x7ffcd8abaec0
root [1] _file0->ls()
TFile**		g.root	
 TFile*		g.root	
  KEY: TGraph	Graph;1	A Simple Graph Example
root [2] Graph->Draw()
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [3] 

and I get:

As you see the X axis title is correct.

I added canvasses prior to the creation of the TGraphs and now it works. Still think it is weird that that should influence the output on the TBrowser since I do not save the canvas.

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