How to visualize two histograms for comparative analysis?

112 visualizaciones (últimos 30 días)
Alex
Alex el 10 de Abr. de 2018
Comentada: Milagre MANHIQUE el 28 de En. de 2022
Basically I have two datasets and I want to perform a comparative analysis by showing how many data fall under a specific range. Any idea as how to do it?
Thanks Alex
  3 comentarios
Anupam Sharma
Anupam Sharma el 12 de Dic. de 2019
This is not working in following code. I am using it exactly as mentioned above but it shows the second histogram only. Can you help ?
% MATLAB R2019a
% Setup
N = [1:5 10 20 40];
LB = 0;
UB = 3;
n = 10000;
% Generate random variates
X = LB + (UB - LB)*rand(max(N),n);
Sn = cumsum(X);
mu = 1.5;
sigma = .75;
S_1 = mu + sigma.*randn(n, 1)
hist1= histogram(Sn(1,:),'Normalization','pdf','EdgeColor', 'blue', 'FaceColor', 'blue')
hold on
hist2 = histogram(S_1(:), 'EdgeColor', 'green', 'FaceColor', 'green', 'FaceAlpha', 0.2);
Image Analyst
Image Analyst el 12 de Dic. de 2019
Use subplot to put them into different axes.

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 10 de Abr. de 2018
The histograms will tell you that - how many counts in each range. Use histogram() for visualization, or histcounts() and bar().
  3 comentarios
the cyclist
the cyclist el 11 de Abr. de 2018

Here is an example of using Image Analyst's idea of using both histcounts and bar:

x = randn(2000,1);
y = 0.1 + randn(2000,1);
binRange = -3:0.5:3;
hcx = histcounts(x,[binRange Inf]);
hcy = histcounts(y,[binRange Inf]);
figure
bar(binRange,[hcx;hcy]')
Alex
Alex el 11 de Abr. de 2018
Thanks a lot "the cyclist".

Iniciar sesión para comentar.

Más respuestas (1)

the cyclist
the cyclist el 10 de Abr. de 2018
As shown in the documentation for the histogram histogram, you can plot two overlapping histograms on one figure like this
x = randn(2000,1);
y = 1 + randn(5000,1);
h1 = histogram(x);
hold on
h2 = histogram(y);
If you have the Statistics and Machine Learning Toolbox, you can also use the Kolmogorov-Smirnov test to determine whether the CDFs of the two distributions are statistically different.
  4 comentarios
Image Analyst
Image Analyst el 28 de En. de 2022
Try histcounts() and bar()
Milagre MANHIQUE
Milagre MANHIQUE el 28 de En. de 2022
Thank you very much, I will proceed as you advise.
I thank you deeply.
Milagre MANHIQUE

Iniciar sesión para comentar.

Categorías

Más información sobre Data Distribution Plots en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by