How to plot two histograms: one line over another bar?

7 vues (au cours des 30 derniers jours)
Josh
Josh le 4 Avr 2016
Commenté : Josh le 4 Avr 2016
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!

Réponse acceptée

Chad Greene
Chad Greene le 4 Avr 2016
Modifié(e) : Chad Greene le 4 Avr 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)
  1 commentaire
Josh
Josh le 4 Avr 2016
Perfect! Worked just as I wanted. Thank you.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by