Setting titles for TGraphs

Hello. I need to do a very simple task

..........
TGraph *graph = new TGraph(point, x,y);
graph->SetTitle("some title");
graph->GetYaxis()->SetTitle("some title01");  // this does not appaer in my graph
.........
graph->Draw("AL*");
return graph;

Did I miss anything, in the Draw options, maybe? Many thanks.
f

Try:
graph->SetTitle("global title;X axis title;Y axis title;Z axis title");

thank you

Maybe you could try this (I get no problem with the “new Y axis title”):

#include "TGraph.h"
#include "TAxis.h"

TGraph * title(void) {
  Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
  Double_t y[10] = {9,8,7,6,5,4,3,2,1,0};
  TGraph *graph = new TGraph(10, x, y);
  graph->SetTitle("graph title");
  // graph->SetTitle("global title;X axis title;Y axis title;Z axis title");
  graph->GetYaxis()->SetTitle("new Y axis title");
  graph->Draw("AL*");
  return graph;
}

See maybe also: https://root-forum.cern.ch/t/order-of-calling-methods-with-tmultigraph/14724/1

the problem not solved. it does not complain however.
I have both the includes, and this sequence :

............
graph->SetTitle("graph title");
graph->GetYaxis()->SetTitle("new Y axis title");
graph->Draw("AL*");
return graph

Maybe you could try:
graph->GetHistogram()->GetYaxis()->SetTitle("new Y axis title");

Messages in response to above:

Error: Failed to evaluate graph->GetHistogram()
Error: Failed to evaluate graph->GetHistogram()->GetYaxis()
Error: Failed to evaluate graph->GetHistogram()->GetYaxis()->SetTitle(“new Y axis title”)

Try to run this (again, I get no problem with the “new Y axis title”):

#include "TGraph.h"
#include "TAxis.h"
#include "TH1.h"

TGraph * title(void) {
  Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
  Double_t y[10] = {9,8,7,6,5,4,3,2,1,0};
  TGraph *graph = new TGraph(10, x, y);
  graph->SetTitle("graph title");
  // graph->SetTitle("global title;X axis title;Y axis title;Z axis title");
  // graph->GetYaxis()->SetTitle("new Y axis title");
  graph->GetHistogram()->GetYaxis()->SetTitle("new Y axis title");
  graph->Draw("AL*");
  return graph;
}

Note: I add several “#include” statements in order to be able to precompile it using ACLiC (i.e. “root [0] .x title.cxx++”)

the same set of errors. yes, all includes are present.

What’s you ROOT version, Operating System version, compiler version?
(I tried ROOT 5.28 and 5.34 on Linux i686 and x86_64 and gcc 4.4.[36].)

Well, maybe you need to report a bug.

root 5.20
Linux version 2.6.18-238.12.1.el5 (brewbuilder@norob.fnal.gov) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)

This macro works for me on Mac with the ROOT trunck:

{
  Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
  Double_t y[10] = {9,8,7,6,5,4,3,2,1,0};
  TGraph *graph = new TGraph(10, x, y);
  graph->SetTitle("graph title");
  graph->GetHistogram()->GetYaxis()->SetTitle("new Y axis title");
  graph->Draw("AL*");
  return graph;
}


This works while the other suggestions did not.

That’s ok. But when we have to rename a X axis tiltle as tan_beta then what?
How can we write a character type title in Root?

what do you mean ?

I mean to say, If I have to write sin(theta) then how i will write it??
Theta not in text format but in symbolic form.

You’ll need to use the TLateX convention.

In your particular case:

graph->SetTitle("global title;sin(#theta);Y axis title;Z axis title");

Got it. Thankyou.
There is another problem how can we allign a title at centre?

graph->GetXaxis()->CenterTitle(true);

Thanks alot.