![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/364081/image.png)
How to same size of plot and histogram
5 次查看(过去 30 天)
显示 更早的评论
I want to compare my function with given parameters with my histogram with generated random numbers.
So, I want to put these two plots in one figure. But my histogram is on the y-axis much more bigger (around 250) than my fplot (around 2). How can I put them in the same size and compare them? I want to see if my histogram has the same shape as my function.
clear all;
clf
n=1000
t0 = 0.5;
T_A = 1;
b_A = 2;
fun_A2p = @(x) (b_A/T_A).*(x/T_A).^(b_A-1).*(exp(-(x/T_A).^(b_A)));
fun_A3p = @(x) (b_A/(T_A-t0)).*((x-t0)/(T_A-t0)).^(b_A-1).*(exp(-((x-t0)/(T_A-t0)).^(b_A)));
fplot(fun_A2p,[0,10], 'LineWidth',2, "Color", 'b')
hold on
fplot(fun_A3p,[0,10], 'LineWidth',2, "Color", 'r', 'LineStyle', '--')
hold on
for v_T = 1:length(T_A)
for v_b = 1:length(b_A)
data2p(:,v_b,v_T) = wblrnd(v_T,v_b, [n,1]);
data3p(:,v_b,v_T) = wblrnd(v_T,v_b, [n,1]) + t0;
end
end
h1= histogram(data2p);
hold on;
h2= histogram(data3p);
set(h1,'FaceColor',[0 0 1],'EdgeColor',[0 0 1],'facealpha',0.5);
set(h2,'FaceColor',[1 0 0],'EdgeColor',[1 0 0],'facealpha',0.5);
ax = gca;
ax.XLim=[0,5];
ax.YLim=[0,300];
grid on; %Gitter anzeigen
box on; %Rahmen zeigen
title ('Vergleich Dichtefunktion mit Histogram');
xlabel('Lebensdauer t');
ylabel('Dichtefunktion f(x)');
legend('2 parametrisch', '3 parametrisch')
0 个评论
采纳的回答
the cyclist
2020-9-21
I think that using
h1= histogram(data2p,'Normalization','pdf');
h2= histogram(data3p,'Normalization','pdf');
and of course removing
ax.YLim=[0,300];
will get you much closer to what you want.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/364081/image.png)
You could also just use the histcounts function to get the counts, and then the bar function to plot them (applying whatever normalization factor you want).
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!