Best way to present histogram with different realisation number

3 vues (au cours des 30 derniers jours)
Yaser Khojah
Yaser Khojah le 29 Juil 2020
I have two data sets as attached with different number of realisations and i want to compare between them. So, I created their histograms to present their realisations over each other’s as in the figure. However, it is hard to see the difference as the number of frequencies is different. Anyway, to present this better; maybe normalising it. Not really sure!
load('NPV_1000.mat')
load('NPV_10000.mat')
x1 = NPV_1000;
y1 = NPV_10000;
figure
h1 = histogram(x1);
hold on
h2 = histogram(y1);
xlabel('NPV ($B)')
ylabel('Frequency')
legend('1,000','10,000')
  1 commentaire
Adam Danz
Adam Danz le 29 Juil 2020
An alternative to normalization is using two y-axes. See yyaxis.

Connectez-vous pour commenter.

Réponse acceptée

Arthur Roué
Arthur Roué le 29 Juil 2020
You can normalize directly with histogram function by changing Normalization property.
h1 = histogram(x1, 'Normalization', 'probability');
  2 commentaires
Yaser Khojah
Yaser Khojah le 29 Juil 2020
thanks so much, but are they going to have the same bin? and anyway to make them transparent
Arthur Roué
Arthur Roué le 29 Juil 2020
You're welcome. Check for histogram property in documentation, you can control appearance in many ways.
For bin numbers, use 2nd argument :
h1 = histogram(x1, nbBins, 'Normalization', 'probability');

Connectez-vous pour commenter.

Plus de réponses (1)

Steven Lord
Steven Lord le 29 Juil 2020
In the "Plot Multiple Histograms" example on the documentation page for histogram, we show one way to give two histogram objects consistent bins. Another way would be to set the BinEdges property (or specify the edges input) for one of the histogram objects using the BinEdges property of the other.
x = randn(1, 1e5);
y = 1 + randn(1, 1e5);
h1 = histogram(x);
hold on
h2 = histogram(y, h1.BinEdges);

Catégories

En savoir plus sur Data Distribution Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by