Reputation: 33
I need to plot several histograms on the same plot. I like the display the following code generates:
import random
import numpy
from matplotlib import pyplot
x = [random.gauss(3,1) for _ in range(400)]
y = [random.gauss(4,2) for _ in range(400)]
bins = numpy.linspace(-10, 10, 100)
pyplot.hist(x, bins, alpha=0.5)
pyplot.hist(y, bins, alpha=0.5)
pyplot.show()
This code was mentioned on this page:Plot two histograms at the same time with matplotlib Basically I am having trouble plotting the same kind of histograms but for data that looks like:
y1=[20,33,54,34,22]
x1=[0,2,4,6,8]
y2=[28,31,59,14,12]
x2=[0,2,4,6,8]
Using the aforementioned code I could not get the y axis to go above 2.0 strange but I must be making a foolish mistake.
Thanks.
Upvotes: 2
Views: 2221
Reputation: 85603
Probably you are looking for this:
pyplot.bar(x2,y2, color='b', width=2, alpha=0.5)
pyplot.bar(x1,y1, color='r', width=2, alpha=0.5)
pyplot.show()
Upvotes: 1