# Title in TMultigraph

**URL:** <https://root-forum.cern.ch/t/title-in-tmultigraph/15344>\
**Category:** ROOT\
**Created:** [December 7, 2012, 11:45am UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344 "2012-12-07T11:45:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![japdhaes](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/j/a88e4f/32.png) [@japdhaes](https://root-forum.cern.ch/u/japdhaes)\
**Post date:** [December 7, 2012, 11:45am UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/1 "2012-12-07T11:45:41Z")

</div>

Hi,

I’m unable to draw a title above a TMultiGraph. How are they added?

First I create a TMultiGraph, then I add 4 TGraph’s to it, then I use TMultiGraph::SetTitle(“title”), but none appears above my graph. When I use the GUI canvas and use the menu \< SetTitle, “title” is already filled in…

Thanks,  
Japdhaes

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [December 7, 2012, 12:34pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/2 "2012-12-07T12:34:45Z")

</div>

[url][Order of calling methods with TMultiGraph](https://root-forum.cern.ch/t/order-of-calling-methods-with-tmultigraph/14724/2)

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [December 11, 2012, 5:01pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/3 "2012-12-11T17:01:11Z")

</div>

Is this a bug then?

---

<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:** [December 11, 2012, 5:06pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/4 "2012-12-11T17:06:55Z")

</div>

Example:

```auto

{
   TCanvas *c2 = new TCanvas("c2","c2",600,400);

   TGraph *g[3];
   Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
   Double_t y[10] = {1,2,3,4,5,5,4,3,2,1};
   TMultiGraph *mg = new TMultiGraph();
   for (int i=0; i<3; i++) {
      g[i] = new TGraph(10, x, y);
      g[i]->SetMarkerStyle(20);
      g[i]->SetMarkerColor(i+2);
      for (int j=0; j<10; j++) y[j] = y[j]-1;
      mg->Add(g[i]);
   }
   mg->Draw("APL");
   mg->GetXaxis()->SetTitle("E_{#gamma} (GeV)");
   mg->GetYaxis()->SetTitle("Coefficients");
   mg->GetHistogram()->SetTitle("Global title");
}

```

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [December 11, 2012, 5:10pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/5 "2012-12-11T17:10:11Z")

</div>

Your example looks like a workaround to me. Does this mean the TGraphPainter ignores the TNamed::fName for TMultiGraph?

---

<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:** [December 11, 2012, 5:15pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/6 "2012-12-11T17:15:17Z")

</div>

No it is the right way. TMultiGraph is on a list of graph. When you draw a TMultiGraph, the first thing drawn is an empty histogram to draw the frame. The global title is hold by this histogram. Them the graphs are drawn sequentially in that frame.

---

<div class="post-metadata">

**Author:** ![ksmith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ksmith/32/12567_2.png) [@ksmith](https://root-forum.cern.ch/u/ksmith)\
**Post date:** [December 11, 2012, 5:19pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/7 "2012-12-11T17:19:07Z")

</div>

Should that histogram then be assigned the title from the TMultiGraph constructor?

---

<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:** [December 11, 2012, 5:24pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/8 "2012-12-11T17:24:01Z")

</div>

It is build at drawing time only because the limits can change if a new graph is added for instance.

---

<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:** [December 11, 2012, 5:24pm UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/9 "2012-12-11T17:24:42Z")

</div>

But your point makes sense … I will check

---

<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:** [December 12, 2012, 8:58am UTC](https://root-forum.cern.ch/t/title-in-tmultigraph/15344/10 "2012-12-12T08:58:36Z")

</div>

In fact you should do:

```auto
   TCanvas *c2 = new TCanvas("c2","c2",600,400);

   TGraph *g[3];
   Double_t x[10] = {0,1,2,3,4,5,6,7,8,9};
   Double_t y[10] = {1,2,3,4,5,5,4,3,2,1};
   TMultiGraph *mg = new TMultiGraph();
   mg->SetTitle("Global title; X Axis; Y Axis");
   for (int i=0; i<3; i++) {
      g[i] = new TGraph(10, x, y);
      g[i]->SetMarkerStyle(20);
      g[i]->SetMarkerColor(i+2);
      for (int j=0; j<10; j++) y[j] = y[j]-1;
      mg->Add(g[i]);
   }
   mg->Draw("APL");

```
