Open
Description
The example code provided in simple_numpy.py might not meet the criteria for high coupling, as it is very similar to the code in simple_2d.py. I recommend you to delete this redundancy example OR possibly add more comments to the simple_2d.py like this:
import boost_histogram as bh
import matplotlib.pyplot as plt
import numpy as np
# Create 2d-histogram with two axes with 20 equidistant bins from -3 to 3
h = bh.Histogram(
bh.axis.Regular(50, -3, 3, metadata="x"), bh.axis.Regular(50, -3, 3, metadata="y")
)
# Generate some Numpy arrays with data to fill into histogram,
# in this case normal distributed random numbers in x and y
x = np.random.randn(1_000_000)
y = np.random.randn(1_000_000)
# Fill histogram with Numpy arrays, this is very fast
h.fill(x, y)
# Get numpy.histogram compatible representation of the histogram
# or create a view of the counts (no copy involved)
w, x, y = h.to_numpy()
# x = h.axes[0].edges
# y = h.axes[1].edges
# w = h.view()
# Draw the count matrix
fig, ax = plt.subplots()
mesh = ax.pcolormesh(x, y, w.T)
ax.set_xlabel(h.axes[0].metadata)
ax.set_ylabel(h.axes[1].metadata)
fig.colorbar(mesh)
plt.savefig("simple_2d.png")
Metadata
Metadata
Assignees
Type
Projects
Status
No status