# Combine TMultiGraphs

**URL:** <https://root-forum.cern.ch/t/combine-tmultigraphs/54676>\
**Category:** Newbie\
**Created:** [April 28, 2023, 5:20pm UTC](https://root-forum.cern.ch/t/combine-tmultigraphs/54676 "2023-04-28T17:20:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex14](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/3ab097/32.png) [@alex14](https://root-forum.cern.ch/u/alex14)\
**Post date:** [April 28, 2023, 5:20pm UTC](https://root-forum.cern.ch/t/combine-tmultigraphs/54676/1 "2023-04-28T17:20:08Z")

</div>

Hi all,

I have a problem with plotting several TMultiGraphs on one canvas (combining them). I have 5 TMultiGraphs in 5 different files. In a macro, I try to call them and plot them together on one canvas, but I get a \*\*\* Break \*\*\* segmentation violation. So, I assume this cannot be done for TMultiGraphs as for TGraphs. Also, I am calling them into the macro as TGraphs, but they are not TGraphs. I apologize for this beginner’s questions. I appreciate the help.

Here is an example of my code:

```auto
void mean()
{
   auto c1 = new TCanvas();

  TFile *f1 = new TFile("0.7.root");
  TGraph *gr1 = (TGraph*)f1->Get("ca2");
  gr1->SetName("gr1");

  TFile *f2 = new TFile("0.8.root");
  TGraph *gr2 = (TGraph*)f2->Get("ca1");
  gr2->SetName("gr2");

  TFile *f3 = new TFile("0.9.root");
  TGraph *gr3 = (TGraph*)f3->Get("ca4");
  gr3->SetName("gr3");

  TFile *f4 = new TFile("0.65.root");
  TGraph *gr4 = (TGraph*)f4->Get("ca5");
  gr4->SetName("gr4");

  TFile *f5 = new TFile("0.85.root");
  TGraph *gr5 = (TGraph*)f5->Get("ca3");
  gr5->SetName("gr5");

   gr1->SetMarkerStyle(20); gr1->SetMarkerColor(kRed); gr1->SetMarkerSize(1.3);
   gr2->SetMarkerStyle(21); gr2->SetMarkerColor(kBlue); gr2->SetMarkerSize(1.3);
   gr3->SetMarkerStyle(22); gr3->SetMarkerColor(kBlack); gr3->SetMarkerSize(1.3);
   gr4->SetMarkerStyle(23); gr4->SetMarkerColor(kOrange); gr4->SetMarkerSize(1.3);
   gr5->SetMarkerStyle(33); gr5->SetMarkerColor(kGreen); gr5->SetMarkerSize(1.3);

  TMultiGraph *mg = new TMultiGraph();
  mg->Add(gr1);
  mg->Add(gr2);
  mg->Add(gr3);
  mg->Add(gr4);
  mg->Add(gr5);
  mg->Draw("AP");
}

```

---

<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:** [April 28, 2023, 7:09pm UTC](https://root-forum.cern.ch/t/combine-tmultigraphs/54676/2 "2023-04-28T19:09:56Z")

</div>

Attach the output of:  
`rootls -l 0.7.root 0.8.root 0.9.root 0.65.root 0.85.root`
