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_code
9##
10## \date July 2025
11## \author Alberto Ferro, Nursena Bitirgen
12
13import matplotlib.pyplot as plt
14import mplhep as hep
15import numpy as np
16import ROOT
17
20fig, ax1 = plt.subplots(figsize=(10, 6))
21
22h1 = ROOT.TH1F("h1", "my histogram", 100, -3, 3)
23
24h1[...] = np.histogram(np.random.normal(0, 1, 10000), range=(-3, 3), bins=100)[0]
25
26hep.histplot(h1, ax=ax1, histtype="fill", color="white", edgecolor="blue", linewidth=1.5, alpha=0.5)
27
28hint1 = ROOT.TH1F("hint1", "h1 bins integral", 100, -3, 3)
29
30hint1[...] = np.cumsum(h1.values())
31
32ax2 = ax1.twinx()
33hep.histplot(hint1, ax=ax2, histtype="errorbar", color="red", marker="+", markersize=3)
34
35ax1.set_xlim(-3, 3)
36plt.title("Histogram with Cumulative Sum")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.