# Draw two histograms in same canvas from two different root files

**URL:** <https://root-forum.cern.ch/t/draw-two-histograms-in-same-canvas-from-two-different-root-files/34900>\
**Category:** Newbie\
**Created:** [June 28, 2019, 10:30am UTC](https://root-forum.cern.ch/t/draw-two-histograms-in-same-canvas-from-two-different-root-files/34900 "2019-06-28T10:30:57Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [June 28, 2019, 10:42am UTC](https://root-forum.cern.ch/t/draw-two-histograms-in-same-canvas-from-two-different-root-files/34900/3 "2019-06-28T10:42:58Z")

</div>

Hi,  
I attached below a modified version of your code. (Remember to put you code between two ``` in this way will appear highlited).

there are 3 main point

- I added two `;` after the opening of the files.
- When you use Get() to get the histogram recast as a TH1D and not a TCanvas, otherwise you cannot the TH1D methods.
- the Draw is made using the TH1D pointer and not the name of the histogram in the file.

```auto
void macro()
{
    
    TFile *f1 = TFile::Open("first.root");
    TH1D *h1= (TH1D*)f1->Get("h1");
    h1->Draw("hist l");
    h1->SetLineWidth(3);
    h1->SetLineColor(2);
    
    TFile *f2 = TFile::Open("second.root");
    TH1D *h2 = (TH1D*)f2->Get("h1");
    h2->SetLineWidth(2);
    h2->SetLineColor(4);
    h2->Draw("hist l same");
    
}

```

---

_[View the full topic](https://root-forum.cern.ch/t/draw-two-histograms-in-same-canvas-from-two-different-root-files/34900)._
