0
$\begingroup$

I have been using SmoothHistogram to plot the probability density function $P(x)$ of some experimental data. On the y-axis, I would like to have $\log(P(x))$ instead of $P(x)$. I do not want a log scale: the y-axis would have negative values. This is an example of code I have been using:

SmoothHistogram[Table[RandomVariate[NormalDistribution[]], {it, 1,10^5}], Automatic, "PDF", Frame -> True, PlotRange -> All, FrameLabel -> {"x", "p(x)"}]

Maybe I could try to extract information from SmoothHistogram and use ListPlot?

I've been using Mathematica 10.0 . Thank you.

$\endgroup$
0
2
$\begingroup$
$Version

(* "12.2.0 for Mac OS X x86 (64-bit) (December 12, 2020)" *)

Clear["Global`"]

There is no need to use Table with RandomVariate to generate multiple values.

SeedRandom[1234];

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

SmoothHistogram[data, Automatic, "PDF", Frame -> True, PlotRange -> All, 
 FrameLabel -> {"x", "p(x)"}]

enter image description here

The distribution corresponding to SmoothHistogram is SmoothKernelDistribution

Plot[PDF[SmoothKernelDistribution[data], x], {x, -4, 4}, Frame -> True, 
 PlotRange -> All, FrameLabel -> {"x", "p(x)"}]

enter image description here

Plotting the Log of the PDF is straightforward.

Plot[Log@PDF[SmoothKernelDistribution[data], x], {x, -4, 4}, Frame -> True, 
 PlotRange -> All, FrameLabel -> {"x", "Log(p(x))"}]

enter image description here

$\endgroup$

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.