Skip to content

Instantly share code, notes, and snippets.

@jaredjburgess
Last active February 23, 2016 19:38
Show Gist options
  • Save jaredjburgess/52e6afe440c5ad3d291c to your computer and use it in GitHub Desktop.
Save jaredjburgess/52e6afe440c5ad3d291c to your computer and use it in GitHub Desktop.
Normalised histogram using matplotlib.pyplot.hist and numpy weights
import numpy as np
import matplotlib.pyplot as plt
counts = [10, 8, 6, 14]
weights = np.ones_like(counts) / float(len(counts))
plt.figure(figsize=(10, 5))
plt.hist(counts, bins=range(1, max(counts)+2), align='left', weights=weights)
plt.xticks(range(1, max(counts)+1))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment