First, we have to import some libraries. "rootpy" is a pythonic wrapper around the ROOT library. In this example, we will use this library instead of the more low-level approach of directly importing "ROOT" and using helpers from "root_numpy".
import numpy as np from rootpy.plotting import Hist2D, Canvas
Welcome to JupyROOT 6.18/00
We then create a simple 2D histogram over two dimensional random data and plot the output.
# Create output canvas canvas = Canvas() # Fill a ROOT histogram from a NumPy array hist = Hist2D(20, -3, 3, 20, -3, 3) hist.fill_array(np.random.randn(1000000, 2)) # Draw histogram into canvas hist.Draw('LEGO2') # Draw canvas canvas.Draw()
This page originated from the notebook root.ipynb which is attached to this page for safe keeping.