How to make a composite probability density plot?
29 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
VBBV
le 31 Déc 2025 à 13:57
Déplacé(e) : VBBV
le 31 Déc 2025 à 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])
Réponses (1)
VBBV
le 31 Déc 2025 à 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 commentaires
Voir également
Catégories
En savoir plus sur Data Distribution Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
