# Plot mean and max values of TGraphs in a TMultiGraph

**URL:** <https://root-forum.cern.ch/t/plot-mean-and-max-values-of-tgraphs-in-a-tmultigraph/32517>\
**Category:** Newbie\
**Created:** [January 31, 2019, 1:08am UTC](https://root-forum.cern.ch/t/plot-mean-and-max-values-of-tgraphs-in-a-tmultigraph/32517 "2019-01-31T01:08:20Z")\
**Posts on this page:** 1\
**Showing post:** 5

<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:** [February 1, 2019, 8:53am UTC](https://root-forum.cern.ch/t/plot-mean-and-max-values-of-tgraphs-in-a-tmultigraph/32517/5 "2019-02-01T08:53:26Z")

</div>

There is not setting to have the grid on a 3D plot like that.  
But it can be easily drawn with 3D lines too.

```auto
void multigraph3D()
{
   auto C = new TCanvas("C","C",200,10,700,500);

   auto mg = new TMultiGraph();

   auto gr1 = new TGraph(); gr1->SetLineColor(kBlue);
   auto gr2 = new TGraph(); gr2->SetLineColor(kRed);
   auto gr3 = new TGraph(); gr3->SetLineColor(kGreen);
   auto gr4 = new TGraph(); gr4->SetLineColor(kOrange);

   Double_t dx = 6.28/100;
   Double_t x = -3.14;

   for (int i=0; i<=100; i++) {
      x = x+dx;
      gr1->SetPoint(i,x,2.*TMath::Sin(x));
      gr2->SetPoint(i,x,TMath::Cos(x));
      gr3->SetPoint(i,x,TMath::Cos(x*x));
      gr4->SetPoint(i,x,TMath::Cos(x*x*x));
   }

   mg->Add(gr4); gr4->SetTitle("Cos(x*x*x)"); gr4->SetLineWidth(3);
   mg->Add(gr3); gr3->SetTitle("Cos(x*x)") ; gr3->SetLineWidth(3);
   mg->Add(gr2); gr2->SetTitle("Cos(x)") ; gr2->SetLineWidth(3);
   mg->Add(gr1); gr1->SetTitle("2*Sin(x)") ; gr1->SetLineWidth(3);

   mg->Draw("a fb l3d");
   double xl[4] = {0.5,1.5,2.5,3.5};
   double yl[4] = {0.,1,-1,0};
   double zl[4] = {0.,0.,0.,0.};
   auto *pl3 = new TPolyLine3D(4, xl, yl, zl);
   pl3->SetLineColor(kOrange+2);
   pl3->SetLineWidth(3);
   pl3->SetLineStyle(3);

   pl3->Draw();

   // Draw grid
   for (double yg=-3; yg<=3; yg++) {
      auto *lg3 = new TPolyLine3D(2);
      lg3->SetLineStyle(3);
      lg3->SetPoint(0,0,yg,-2);
      lg3->SetPoint(1,4,yg,-2);
      lg3->Draw();
   }
  for (double xg=1; xg<=3; xg++) {
      auto *lg3 = new TPolyLine3D(2);
      lg3->SetLineStyle(3);
      lg3->SetPoint(0,xg,-3,-2);
      lg3->SetPoint(1,xg,3,-2);
      lg3->Draw();
   }
}

```

 ![11](https://root-forum.cern.ch/uploads/default/original/3X/1/c/1c1590132e4997be305d8e8e79374cd4c18d1ab2.jpeg)

---

_[View the full topic](https://root-forum.cern.ch/t/plot-mean-and-max-values-of-tgraphs-in-a-tmultigraph/32517)._
