How can I extend the normal distribution curve in histfit function

9 ビュー (過去 30 日間)
Alberto
Alberto 2014 年 8 月 2 日
コメント済み: Alberto 2014 年 8 月 5 日
Hello, I am trying to plot a normal distribution curve together with a kernel density and the histogram of the data using the code below. However, when I plot them I can see that the normal distribution curve is truncated up to some point as you can see in the image below. My question is How can I extend this curve a little bit more?
figHandler=figure;
h1=histfit(rho_fec(:,1),30,'normal');
set(h1(1),'facecolor',[.8 .8 1]);
set(h1(2), 'color' ,'b');
hold on;
h2=histfit(rho_fec(:,1),30,'kernel');
set(h2(1),'facecolor',[.8 .8 1]);
uistack(h1,'up');
axis([0.3 0.6 0 110]);
xlabel('$\hat{\rho}$','Interpreter','latex','FontSize',13)
l=legend([h1(2) h2(2)],' Std. Normal density',' Kernel density',...
'Location',[0.67,0.80,0.1,0.1]);
set(l,'Interpreter','latex','FontSize',14)
legend boxoff;
hold off;

採用された回答

the cyclist
the cyclist 2014 年 8 月 3 日
編集済み: the cyclist 2014 年 8 月 3 日
Hm. Definitely strange. I can't replicate it by just poking around randomly. It might depend on your data. You could try taking a look at the (x,y) data generated by histfit(), using
get(h1(2),'XData')
get(h1(2),'YData')
and see what they look like. Given your input argument, I would expect both XData and YData to be vectors of length 30. I wonder if there is a very tiny value or some weird NaN getting in there. If so, you could put a breakpoint inside the histfit() function and see what's going on.
  3 件のコメント
the cyclist
the cyclist 2014 年 8 月 5 日
Looking inside the histfit() function, I see the following code that defines the range of x:
% Find range for plotting
q = icdf(pd,[0.0013499 0.99865]); % three-sigma range for normal distribution
x = linspace(q(1),q(2));
It's semi-arbitrarily plotting a 3-sigma portion of the distribution.
If you want to do something different, you could modify and save your own version of that file.
Alberto
Alberto 2014 年 8 月 5 日
Effectively, increasing the upper and decreasing the lower limits the curve was plotted in more points. Thank you very much.

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2014 年 8 月 2 日
I don't think the issue is that the normal curve is truncated. I think the issue is that the histogram is plotted in front of the normal curve.
I expect you can use the uistack() command -- as you did earlier -- to move the normal curve to the front.
  1 件のコメント
Alberto
Alberto 2014 年 8 月 3 日
Thank you for your answer, but apparently this is not the problem, sorry for not attaching a complete image of the plot. In the image below you can see how both curves are in front of the histogram.
Or maybe i am missing something like sending the histogram down, but I think I tried all I thought it would work with -uistack- and did not have success.
Thank you for your help...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDescriptive Statistics and Visualization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by