Files
histogram/examples/python_example_1d.py
Hans Dembinski 367131c336 fixing travis
2017-06-06 15:22:50 +02:00

19 lines
614 B
Python

import histogram as hg
import numpy as np
h = hg.histogram(hg.axis.regular(10, -3, 3, "x"))
h.fill(np.random.randn(1000))
x = np.array(h.axis(0)) # axis instances behave like sequences
y = np.asarray(h) # creates a view (no copy involved)
y = y[:h.axis(0).bins] # cut off underflow/overflow bins; y[:-2] also works
y = np.append(y, [0]) # extra zero needed by matplotlib's plot(...) function
try:
import matplotlib.pyplot as plt
plt.plot(x, y, drawstyle="steps-post")
plt.xlabel(h.axis(0).label)
plt.ylabel("counts")
plt.savefig("example_1d_python.png")
except ImportError:
pass