
How to plot two histograms: one line over another bar?
7 views (last 30 days)
Show older comments
I have been searching for a way to graph two histograms on the same figure. Most of them are two bar graphs either side-by-side or on top of each other; however, I want one set of data to be a traditional bar graph and the other to be a line drawing overlaid on top of the bar graph. Both data are roughly normal distributions, but are of different size.
For instance, I have one dataset that is 993x1 and the other 66x1. I want to show that that smaller dataset (the line graph) is similar to the larger dataset (the bar graph).
Does anyone have any suggestions on how to do this?
Thanks!
0 Comments
Accepted Answer
Chad Greene
on 4 Apr 2016
Edited: Chad Greene
on 4 Apr 2016
Here are two distributions, x1 and x2:
x1 = randn(993,1);
x2 = randn(66,1);
hist(x1,-5:.5:5)
hold on
h = hist(x2,-5:.5:5);
plot(-5:0.5:5,h,'r-','linewidth',2)

More Answers (0)
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!