How to make a composite probability density plot?
25 次查看(过去 30 天)
显示 更早的评论
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
2025-12-31,13:57
移动:VBBV
2025-12-31,14:58
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
2025-12-31,13:46
@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])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
