How to visualize two histograms for comparative analysis?
이전 댓글 표시
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
Pieter VL
2018년 12월 6일
You can change the transparancy of the bars of the second histogram using the 'FaceAlpha' parameter to create a visible overlay as follows:
hist1 = histogram( ..., 'EdgeColor', 'blue', 'FaceColor', 'blue' );
hold on;
hist2 = histogram( ..., 'EdgeColor', 'green', 'FaceColor', 'green', 'FaceAlpha', 0.2 );
Anupam Sharma
2019년 12월 12일
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
2019년 12월 12일
Use subplot to put them into different axes.
채택된 답변
추가 답변 (1개)
the cyclist
2018년 4월 10일
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
Alex
2018년 4월 11일
Milagre MANHIQUE
2022년 1월 28일
Hallo Matlab community
I would like to plot two histograms from two different datasets on the same graph (overlapping and transparent), but each of the histograms containing the respective fit curve.
I tried to use the histfit command on each dataset but was unsuccessful.
I ask for help please
Image Analyst
2022년 1월 28일
Try histcounts() and bar()
Milagre MANHIQUE
2022년 1월 28일
Thank you very much, I will proceed as you advise.
I thank you deeply.
Milagre MANHIQUE
카테고리
도움말 센터 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
