For example, we have a list of values

data = RandomVariate[NormalDistribution[], 10^3];



By default plot the PDF of data like this

enter image description here

But there is also options to plot the Intensity of data using

SmoothHistogram[data, Automatic, "Intensity"]

which gives

enter image description here

This intensity curve is what I want. But I also want the function of this intensity curve, so I can to subtract two such intensity curve function to plot a new one.

I look into the doc, it seems that SmoothKernelDistribution suite the needs. For example, let



Plot[PDF[dist, {x}], {x, -3, 3}]


enter image description here

Which is equivalent to SmoothHistogram[data]. But how to get equivalent Intensity plot using SmoothKernelDistribution? Is there a complete list of function that is supported by SmoothKernelDistribution like PDF?


data = RandomVariate[NormalDistribution[], 10^3];

{xmin, xmax} = MinMax@data;

smhist = SmoothHistogram[data, Automatic, "Intensity"]

enter image description here

p[x_] = PDF[SmoothKernelDistribution[data], x];

The factor required to scale the PDF to the intensity curve is

amp = Divide @@
   ((Cases[#, Line[pts_] :> pts, Infinity][[1, All, 2]] // 
        Max) & /@
     {smhist, Plot[p[x], {x, xmin, xmax}]});

intensity[x_] = amp*p[x];

Plot[intensity[x], {x, xmin, xmax}]

enter image description here

EDIT: A more straightforward approach is to use the points from smhist to define an InterpolatingFunction.

int = Interpolation[Cases[smhist, Line[pts_] :> pts, Infinity][[1]]];

Plot[int[x], {x, xmin, xmax}]

enter image description here

  • $\begingroup$ Wow, powerful postprocessing. So there is no built in statistic function corresponding to "indensity"? $\endgroup$
    – matheorem
    Apr 23 '19 at 0:05

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.