Skip to content

Instantly share code, notes, and snippets.

@nomeyer
Last active February 12, 2016 13:39
Show Gist options
  • Save nomeyer/031d97e4cf3170243fa4 to your computer and use it in GitHub Desktop.
Save nomeyer/031d97e4cf3170243fa4 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