# Store already plotted TGraphs in a root file

**URL:** <https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974>\
**Category:** Newbie\
**Created:** [October 15, 2022, 4:42am UTC](https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974 "2022-10-15T04:42:40Z")\
**Posts on this page:** 6\
**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:** [October 15, 2022, 4:42am UTC](https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974/1 "2022-10-15T04:42:40Z")

</div>

Hello,

I have a question regarding TGraphs and storing them in the root file. Anyway, I have created two TGraphs separately, and I want to create a new root file and store the graphs there. I have started with a code

TFile \*f = TFile::Open(“Selection.root”, “RECREATE");

I don’t know what to do after that. I have tried several examples from the forum and tutorials, but nothing seems to work. That’s because I want to store already plotted graphs. I appreciate the help.

---

<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:** [October 15, 2022, 4:47am UTC](https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974/2 "2022-10-15T04:47:59Z")

</div>

`f->cd(); graph1->Write("MyGraph1"); graph2->Write("MyGraph2"); delete f;`

---

<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:** [October 15, 2022, 5:07am UTC](https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974/3 "2022-10-15T05:07:11Z")

</div>

Hi Coyote,  
thank you so much for your answer. I have tried this but I’m getting this error:  
**use of undeclared identifier ‘graph1’**  
**use of undeclared identifier ‘graph2’**

---

<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:** [October 15, 2022, 5:15am UTC](https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974/4 "2022-10-15T05:15:05Z")

</div>

These should be pointers to your real graphs.

---

<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:** [October 15, 2022, 2:46pm UTC](https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974/5 "2022-10-15T14:46:48Z")

</div>

Thank you again for your quick answer. I tried to put the TGraphs’ titles and also the names of the cpp files as pointers, but root didn’t find them. Am I making a mistake?

---

<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:** [October 15, 2022, 4:12pm UTC](https://root-forum.cern.ch/t/store-already-plotted-tgraphs-in-a-root-file/51974/6 "2022-10-15T16:12:06Z")

</div>

I managed to solve it. I’ve made a simple mistake. Thanks again!
