9
$\begingroup$

Like in this question, I would like to display a histogram and a smooth histogram in the same plot.

I believe the default “bin height specification” (or $\textit{hspec}$) for Histogram is "Count", and the default “distribution function” (or $\textit{dfun}$) for SmoothHistogram is "PDF".

Documentation for Histogram

Documentation for SmoothHistogram

However, I can’t find an analog for "Count" in SmoothHistogram. There was a suggestion to use "Intensity", but it doesn’t scale the curve correctly:

What is the best way to scale the SmoothHistogram curve up to the height of the Histogram bars?

$\endgroup$
11
$\begingroup$

If you really want to, you can scale up from the "PDF". The "scaling" factor depends on how the Histogram was binned, but we can use HistogramDistribution to easily get this information (there might even be a much easier way):

δ = Length[foo]/(HistogramDistribution[foo]["PDFValues"] // Total)
(* 150. *)

and then the ScalingFunctions option

Show[Histogram[foo], 
 SmoothHistogram[foo, Automatic, "PDF", 
  ScalingFunctions -> {Identity, {#*δ &, #/δ &}}]]

histogram

$\endgroup$
1
$\begingroup$

It would be best to make the Histogram look like the SmoothHistogram as in

Show[Histogram[foo, Automatic, "PDF"], SmoothHistogram[foo]]

Histogram

$\endgroup$
  • $\begingroup$ This doesn’t answer my specific question of how to scale up the SmoothHistogram. The linked question at the top of my post already instructs how to scale the Histogram down using "PDF". $\endgroup$ – hftf Oct 20 '15 at 21:23
  • $\begingroup$ Understood. I'm curious as to why you want to go in that direction. Usually it is the unknown probability density which is the target so going back towards a histogram is not recommended. In addition, the smooth histogram usually is something to replace the histogram rather than displaying both (other than for the purpose of checking that things worked properly). $\endgroup$ – JimB Oct 20 '15 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.