# How to save canvas in tree?

**URL:** <https://root-forum.cern.ch/t/how-to-save-canvas-in-tree/50161>\
**Category:** Newbie\
**Created:** [May 27, 2022, 6:25pm UTC](https://root-forum.cern.ch/t/how-to-save-canvas-in-tree/50161 "2022-05-27T18:25:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divyang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/7ea924/32.png) [@Divyang](https://root-forum.cern.ch/u/Divyang)\
**Post date:** [May 27, 2022, 6:25pm UTC](https://root-forum.cern.ch/t/how-to-save-canvas-in-tree/50161/1 "2022-05-27T18:25:05Z")

</div>

Hi,

I am new to root. I know how to save a histogram but how to save the canvas in the tree or in the root file.

Thanks.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [May 27, 2022, 8:48pm UTC](https://root-forum.cern.ch/t/how-to-save-canvas-in-tree/50161/2 "2022-05-27T20:48:57Z")

</div>

You save it in a root file the same way you save a histogram, `canvas->Write()`

---

<div class="post-metadata">

**Author:** ![Divyang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/7ea924/32.png) [@Divyang](https://root-forum.cern.ch/u/Divyang)\
**Post date:** [May 28, 2022, 10:36pm UTC](https://root-forum.cern.ch/t/how-to-save-canvas-in-tree/50161/3 "2022-05-28T22:36:27Z")

</div>

Hi @dastudillo,

Your solution worked, thanks.

I am just curious to know if it is possible to save the canvas or histogram in a tree. I mean currently, I am writing the canvas (or histogram) directly in a root file, without creating a tree. Here is the pseudo-code of what I am doing,

```auto
TFile *f1 = new TFile("test.root", "RECREATE");
TCanvas *can = new TCanvas("can", "can", 750, 500);
// Add histogram to the canvas
can -> Write();

```

As you can notice, there is no `TTree` in the code. It would be more organized if I can save this canvas in different branches of a tree.

Please suggest something. Because my analysis involves a lot of plots.

Thanks,  
Divyang.
