Skip to content

Instantly share code, notes, and snippets.

@alichaudry
Last active March 30, 2016 16:42
Show Gist options
  • Save alichaudry/4d9517cf9ef162e4a159 to your computer and use it in GitHub Desktop.
Save alichaudry/4d9517cf9ef162e4a159 to your computer and use it in GitHub Desktop.
Plot multiple histograms on single chart
"""
Code to plot multiple histograms on a single chart.
Inspired by:
http://stackoverflow.com/questions/6871201/plot-two-histograms-at-the-same-time-with-matplotlib
"""
from __future__ import division
import random
import numpy as np
import matplotlib.pyplot as plt
x = [random.gauss(3,1) for _ in range(400)]
y = [random.gauss(4,2) for _ in range(400)]
bins = np.linspace(-10, 10, 100)
plt.hist(x, bins, alpha=0.5, label='x')
plt.hist(y, bins, alpha=0.5, label='y')
plt.legend(loc='upper right')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment