# Setting titles for TGraphs

**URL:** <https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856>\
**Category:** ROOT\
**Created:** [September 3, 2012, 8:41am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856 "2012-09-03T08:41:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fclopez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fclopez](https://root-forum.cern.ch/u/fclopez)\
**Post date:** [September 3, 2012, 8:41am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/1 "2012-09-03T08:41:12Z")

</div>

Hello. I need to do a very simple task

```auto
..........
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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 3, 2012, 9:04am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/2 "2012-09-03T09:04:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fclopez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fclopez](https://root-forum.cern.ch/u/fclopez)\
**Post date:** [September 3, 2012, 9:53am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/3 "2012-09-03T09:53:56Z")

</div>

thank you

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 3, 2012, 10:27am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/4 "2012-09-03T10:27:35Z")

</div>

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

```cpp
#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](https://root-forum.cern.ch/t/order-of-calling-methods-with-tmultigraph/14724/1)

---

<div class="post-metadata">

**Author:** ![fclopez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fclopez](https://root-forum.cern.ch/u/fclopez)\
**Post date:** [September 3, 2012, 10:43am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/5 "2012-09-03T10:43:12Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 3, 2012, 10:51am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/6 "2012-09-03T10:51:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fclopez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fclopez](https://root-forum.cern.ch/u/fclopez)\
**Post date:** [September 3, 2012, 10:56am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/7 "2012-09-03T10:56:22Z")

</div>

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”)

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 3, 2012, 10:59am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/8 "2012-09-03T10:59:10Z")

</div>

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

```cpp
#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++`”)

---

<div class="post-metadata">

**Author:** ![fclopez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fclopez](https://root-forum.cern.ch/u/fclopez)\
**Post date:** [September 3, 2012, 11:03am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/9 "2012-09-03T11:03:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [September 3, 2012, 11:06am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/10 "2012-09-03T11:06:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![fclopez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fclopez](https://root-forum.cern.ch/u/fclopez)\
**Post date:** [September 3, 2012, 11:11am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/11 "2012-09-03T11:11:53Z")

</div>

root 5.20  
Linux version 2.6.18-238.12.1.el5 ([brewbuilder@norob.fnal.gov](mailto: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)

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [September 3, 2012, 11:27am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/12 "2012-09-03T11:27:54Z")

</div>

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

```auto
{
  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;
}
```

 ![](https://root-forum.cern.ch/uploads/default/original/2X/c/c840f7713617560661bc5b4206ebbe0f77f4a1a7.gif)

---

<div class="post-metadata">

**Author:** ![fclopez](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/f/4bbf92/32.png) [@fclopez](https://root-forum.cern.ch/u/fclopez)\
**Post date:** [September 3, 2012, 3:18pm UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/13 "2012-09-03T15:18:01Z")

</div>

> [@Pepe Le Pew](#):
>
> Try:  
> graph-\>SetTitle(“global title;X axis title;Y axis title;Z axis title”);

This works while the other suggestions did not.

---

<div class="post-metadata">

**Author:** ![Danish](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danish/32/19154_2.png) [@Danish](https://root-forum.cern.ch/u/Danish)\
**Post date:** [April 24, 2020, 11:40am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/14 "2020-04-24T11:40:23Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 24, 2020, 11:52am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/15 "2020-04-24T11:52:00Z")

</div>

> [@Danish](#):
>
> How can we write a character type title in Root?

what do you mean ?

---

<div class="post-metadata">

**Author:** ![Danish](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danish/32/19154_2.png) [@Danish](https://root-forum.cern.ch/u/Danish)\
**Post date:** [April 24, 2020, 11:55am UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/16 "2020-04-24T11:55:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 24, 2020, 12:04pm UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/17 "2020-04-24T12:04:42Z")

</div>

You’ll need to use the [TLateX convention](https://root.cern.ch/doc/master/classTLatex.html#L7).

In your particular case:

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

```

---

<div class="post-metadata">

**Author:** ![Danish](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danish/32/19154_2.png) [@Danish](https://root-forum.cern.ch/u/Danish)\
**Post date:** [April 24, 2020, 12:07pm UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/18 "2020-04-24T12:07:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 24, 2020, 12:15pm UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/19 "2020-04-24T12:15:37Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![Danish](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danish/32/19154_2.png) [@Danish](https://root-forum.cern.ch/u/Danish)\
**Post date:** [April 24, 2020, 12:24pm UTC](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856/20 "2020-04-24T12:24:19Z")

</div>

Thanks alot.

[Next page](https://root-forum.cern.ch/t/setting-titles-for-tgraphs/14856.md?page=2)
