How to make a composite probability density plot?

Hi everyone,
May someone help me here ...
I have data in two columns, I am interested to make a probability density plot (hisogram along with bestfit) for 2 different parameteres (data attached here). I made a try using probability values but then I have a probelm related with the orginal x-axis.
ax1 = subplot(1,2,1); % Left subplot
histfit(ax1,a,10,'normal')
title(ax1,'Left Subplot')
ax2 = subplot(1,2,2); % Right subplot
histfit(ax2,b,10,'normal')
title(ax2,'Right Subplot')
The required results should be like attched figure ..

댓글 수: 1

VBBV
VBBV 2025년 12월 31일
이동: VBBV 2025년 12월 31일
data = webread("https://in.mathworks.com/matlabcentral/answers/uploaded_files/481458/data.txt");
a = str2num(data);
x = linspace(-20,20,length(a));
h1=histogram(a(:,1),5);
h1.BinCounts = h1.BinCounts/max(h1.BinCounts); % Normalize the bin counts
h2.FaceColor = [0.1 0.5 0.1];
h1.EdgeColor = 'None';
mu1 = mean(a(:,1));
sd1 = std(a(:,1));
hold('on')
y=pdf('Normal',x,mu1,sd1);
p1=plot(x,y,linewidth=2);
hold on
h2=histogram(a(:,2),5);
h2.BinCounts = h2.BinCounts/max(h2.BinCounts);
h2.FaceColor = [0.1 0.5 0.1];
h2.EdgeColor = 'None';
mu2 = mean(a(:,2));
sd2 = std(a(:,2));
hold('on')
y=pdf('Normal',x,mu2,sd2);
p2=plot(x,y,linewidth=2);
legend([p1,p2],'A','B')
axis([-20 20 0 0.5])
yticks([0:0.1:0.5])

댓글을 달려면 로그인하십시오.

답변 (1개)

VBBV
VBBV 2025년 12월 31일
@aa You can try this way ,
data = webread("https://in.mathworks.com/matlabcentral/answers/uploaded_files/481458/data.txt");
a = str2num(data);
x = linspace(-20,20,length(a));
h1=histogram(a(:,1),5);
h1.BinCounts = h1.BinCounts/max(h1.BinCounts); % Normalize the bin counts
h2.FaceColor = [0.1 0.5 0.1];
h1.EdgeColor = 'None';
mu1 = mean(a(:,1));
sd1 = std(a(:,1));
hold('on')
y=pdf('Normal',x,mu1,sd1);
p1=plot(x,y,linewidth=2);
hold on
h2=histogram(a(:,2),5);
h2.BinCounts = h2.BinCounts/max(h2.BinCounts);
h2.FaceColor = [0.1 0.5 0.1];
h2.EdgeColor = 'None';
mu2 = mean(a(:,2));
sd2 = std(a(:,2));
hold('on')
y=pdf('Normal',x,mu2,sd2);
p2=plot(x,y,linewidth=2);
legend([p1,p2],'A','B')
axis([-20 20 0 0.5])
yticks([0:0.1:0.5])

카테고리

도움말 센터File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

질문:

aa
2021년 1월 7일

이동:

2025년 12월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by