# Plotting two TH1D together

**URL:** <https://root-forum.cern.ch/t/plotting-two-th1d-together/48024>\
**Category:** Newbie\
**Tags:** python, hist\
**Created:** [December 10, 2021, 2:43pm UTC](https://root-forum.cern.ch/t/plotting-two-th1d-together/48024 "2021-12-10T14:43:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@Miguel](https://root-forum.cern.ch/u/Miguel)\
**Post date:** [December 10, 2021, 2:43pm UTC](https://root-forum.cern.ch/t/plotting-two-th1d-together/48024/1 "2021-12-10T14:43:33Z")

</div>

Hi there!

I have a root file (“data.root”) with two TH1D files on it:

“ICRC\_V2\_hists/Cos theta/data” and "“ICRC\_V2\_hists/Cos theta/MC”

![MC](https://root-forum.cern.ch/uploads/default/original/3X/f/b/fb6fa1c1d2eeb5acde448fff46b27e638165c5fd.png)  
 ![data](https://root-forum.cern.ch/uploads/default/original/3X/9/8/98efc2f20b3c3b50046ae8f5878ac9d9cc70d224.png)

I have made this script to plot the two histograms together:

**import ROOT**  
**import numpy as np**  
**import uproot**  
**import matplotlib.pyplot as plt**

**f = uproot.open(“data.root”)**

**fig, ax = plt.subplots()**

**h\_data = f[“ICRC\_V2\_hists/Cos theta/data”].to\_numpy()**  
**h\_MC = f[“ICRC\_V2\_hists/Cos theta/MC”].to\_numpy()**

**hists = [h\_MC, h\_data]**

**for h in hists :**

\*\* ax.hist(h[1][:-1],\*\*  
\*\* bins = h[1],\*\*  
\*\* weights = h[0],\*\*  
\*\* histtype = ‘step’,\*\*  
\*\* zorder=10)\*\*

**ax.set\_xlabel(‘cos(\theta’)**  
**ax.set\_ylabel(‘Rate [Hz]’)**  
**ax.grid(zorder=0)**

**plt.tight\_layout()**  
**plt.show()**

But the result is something like:

![total](https://root-forum.cern.ch/uploads/default/original/3X/0/3/03b867e86233ddf42d98b0aae5473325fe383798.png)

What I want to do is to give this step format for “MC” but to keep the original dataformat for “data” (I meen, not a bar hist but points with errorbars, as seen above).

How can I do it?

Thanks in advance!

---

<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:** [December 10, 2021, 4:01pm UTC](https://root-forum.cern.ch/t/plotting-two-th1d-together/48024/2 "2021-12-10T16:01:56Z")

</div>

The two separated plots are clearly produced by ROOT graphics but the second plot (grouping the two histograms) seems to be produced by mathplotlib . So that’s not a ROOT question but more a mathplotlib one. Unless you are willing to produce the second plot using ROOT graphics and in that case you can simply do:

```auto
h1->Draw();
h2->Draw("same");

```
