How to make a composite probability density plot?

25 ビュー (過去 30 日間)
aa
aa 2021 年 1 月 7 日
移動済み: VBBV 2025 年 12 月 31 日 14:58
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 日 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
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])

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by