I have produced 3 sets of data which are organised in numpy arrays. I'm interested in plotting the probability distribution of these three sets of data as normed histograms. All three distributions should look almost identical so it seems sensible to plot all three on the same axis for ease of comparison.
By default matplotlib histograms are plotted as bars which makes the image I want look very messy. Hence, my question is whether it is possible to force pyplot.hist to only draw a box/circle/triangle where the top of the bar would be in the default form so I can cleanly display all three distributions on the same graph or whether I have to calculate the histogram data and then plot it separately as a scatter graph.
Thanks in advance.
Best Answer
There are two ways to plot three histograms simultaniously, but both are not what you've asked for. To do what you ask, you must calculate the histogram, e.g. by using
numpy.histogram
, then plot using theplot
method. Usescatter
only if you want to associate other information with your points by setting a size for each point.The first alternative approach to using
hist
involves passing all three data sets at once to thehist
method. Thehist
method then adjusts the widths and placements of each bar so that all three sets are clearly presented.The second alternative is to use the
histtype='step'
option, which makes clear plots for each set.Here is a script demonstrating this:
And here is the resulting plot:
Keep in mind you could do all this with the object oriented interface as well, e.g. make individual subplots, etc.