MATLAB: How to extend the normal distribution curve in histfit function

histfitkernel densitynormal densityplot

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?
set(h1(1),'facecolor',[.8 .8 1]);
set(h1(2), 'color' ,'b');
hold on;
set(h2(1),'facecolor',[.8 .8 1]);
axis([0.3 0.6 0 110]);
l=legend([h1(2) h2(2)],' Std. Normal density',' Kernel density',...
legend boxoff;
hold off;

Best Answer

  • 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
    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.