# Problem with saving graphs

**URL:** <https://root-forum.cern.ch/t/problem-with-saving-graphs/5112>\
**Category:** ROOT\
**Created:** [July 31, 2007, 5:18pm UTC](https://root-forum.cern.ch/t/problem-with-saving-graphs/5112 "2007-07-31T17:18:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nobu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nobu](https://root-forum.cern.ch/u/Nobu)\
**Post date:** [July 31, 2007, 5:18pm UTC](https://root-forum.cern.ch/t/problem-with-saving-graphs/5112/1 "2007-07-31T17:18:48Z")

</div>

Hi,

I would like to save the graphs by ROOT, so I tried “Print” and “SaveAs” commands.  
However, it creates blank png or pdf files without any error messages  
even though it shows the graphs on the screen.  
Would you tell me how to save the graphs?

Here is my macro,

{  
…  
TCanvas \*fCanv[10];  
Int\_t \*xCanDiv;  
Int\_t \*yCanDiv;  
Int\_t xCanSize;  
Int\_t yCanSize;  
…  
name = Form(“Protons\_”);  
…  
…  
name += i;  
fCanv[i] = new TCanvas(name.Data(), name.Data(), xCanSize, yCanSize);  
fCanv[i]-\>SetFillColor(10);  
fCanv[i]-\>Divide(xCanDiv[i], yCanDiv[i]);  
…  
fCanv[i]-\>SaveAs( Form( “%s%s.png”, name.Data(), Polarity.Data() ) );  
fCanv[i]-\>Print( Form( “%s%s.pdf”, name.Data(), Polarity.Data() ) );  
…  
}

---

<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:** [August 1, 2007, 7:02am UTC](https://root-forum.cern.ch/t/problem-with-saving-graphs/5112/2 "2007-08-01T07:02:03Z")

</div>

It should work. Try this:

```auto

{
   c1 = new TCanvas("c1","A Simple Graph Example",200,10,500,300);
   const Int_t n = 20;
   Double_t x[n], y[n];
   for (Int_t i=0;i<n;i++) {
     x[i] = 0.1*i;
     y[i] = sin(x[i]+0.2);
   }
   gr = new TGraph(n,x,y);
   gr->Draw("ALP");
   c1->Print("c1.pdf");
   c1->Print("c1.png");
}
```

It gives the attached results.  
[c1.pdf](https://root-forum.cern.ch/uploads/default/original/2X/4/49deac7a8dd02f4ee9904b8a3e7db6b1bceffdff.pdf) (12.7 KB)  
 ![](https://root-forum.cern.ch/uploads/default/original/2X/d/d2314117c45e3d5180e10a97f4c1d276d25a253c.png)

---

<div class="post-metadata">

**Author:** ![Nobu](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/e9c0ed/32.png) [@Nobu](https://root-forum.cern.ch/u/Nobu)\
**Post date:** [October 8, 2007, 8:17pm UTC](https://root-forum.cern.ch/t/problem-with-saving-graphs/5112/3 "2007-10-08T20:17:16Z")

</div>

Hi,

I am so sorry to reply so late.  
I think the problem is

fCanv[i]-\>SaveAs( Form( “%s%s.png”, name.Data(), Polarity.Data() ) );  
fCanv[i]-\>Print( Form( “%s%s.pdf”, name.Data(), Polarity.Data() ) );

Form() command and the contents of name.Data(), Polarity.Data() .

Thanks anyway!
