title: Distribution fitting and histogram overlay (scaling matter) - MATLAB
body: <p>While trying to overlay pdf (probability density function) values on a histogram I face significant scaling issues as the histogram is barely visible on my chart. This might be due to scaling factors used in the below code, otherwise the density curves would be tiny. I am in a predicament and thus wondering if there is a <strong>better</strong> way to achieve this task without resorting to <strong>adhoc</strong> scaling factor?</p>
  
  <pre><code>bmin=min(b);
  bmx=max(b);
  nrow=length(b);
  nbin=sqrt(nrow);
  pd = fitdist(b,'Normal');
  p = stblfit(b,'ecf');
  x_pdf=[bmin:0.0025:bmax];
  y=pdf(pd,x_pdf);
  hist(b,nrow);
  h = findobj(gca, 'Type','patch');
  h.FaceColor=[0 0 0];
  hold on;
  scale = 0.156*max(y);
  plot(x_pdf,y.*scale,'or');
  hold on;
  scale2 = 0.24*max(y);
  plot(x_pdf,stblpdf(x_pdf,p(1),p(2),p(3),p(4)).*scale2,'k-');
  legend('P&amp;L distribution','Normal fit', 'ecf fit')
  </code></pre>
  
  <p>Thanks</p>