fclopez
September 3, 2012, 8:41am
1
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");
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
fclopez
September 3, 2012, 10:43am
5
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");
fclopez
September 3, 2012, 10:56am
7
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++
”)
fclopez
September 3, 2012, 11:03am
9
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.
fclopez
September 3, 2012, 11:11am
11
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)
couet
September 3, 2012, 11:27am
12
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;
}
fclopez
September 3, 2012, 3:18pm
13
This works while the other suggestions did not.
Danish
April 24, 2020, 11:40am
14
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?
Danish
April 24, 2020, 11:55am
16
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.
couet
April 24, 2020, 12:04pm
17
You’ll need to use the TLateX convention .
In your particular case:
graph->SetTitle("global title;sin(#theta);Y axis title;Z axis title");
Danish
April 24, 2020, 12:07pm
18
Got it. Thankyou.
There is another problem how can we allign a title at centre?
couet
April 24, 2020, 12:15pm
19
graph->GetXaxis()->CenterTitle(true);