Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hist010_TH1_two_scales_uhi.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_hist
3## \notebook
4## Example of macro illustrating how to superimpose two histograms
5## with different scales in the "same" pad.
6## Inspired by work of Rene Brun.
7##
8## \macro_image
9## \macro_code
10##
11## \date July 2025
12## \author Alberto Ferro, Nursena Bitirgen
13
14import matplotlib.pyplot as plt
15import mplhep as hep
16import numpy as np
17import ROOT
18
21fig, ax1 = plt.subplots(figsize=(10, 6))
22
23h1 = ROOT.TH1F("h1", "my histogram", 100, -3, 3)
24
25h1[...] = np.histogram(np.random.normal(0, 1, 10000), range=(-3, 3), bins=100)[0]
26
27hep.histplot(h1, ax=ax1, histtype="fill", color="white", edgecolor="blue", linewidth=1.5, alpha=0.5)
28
29hint1 = ROOT.TH1F("hint1", "h1 bins integral", 100, -3, 3)
30
31hint1[...] = np.cumsum(h1.values())
32
33ax2 = ax1.twinx()
34hep.histplot(hint1, ax=ax2, histtype="errorbar", color="red", marker="+", markersize=3)
35
36ax1.set_xlim(-3, 3)
37plt.title("Histogram with Cumulative Sum")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.