I have some data.I plot the histogram with SmoothHistogram in Mathematica. If the y-axis of the histogram is my p(x) function, I want to plot f(x)=(1/n)ln(p(x)) with Mathematica. I don't know how?!

data = Import["Desktop/kmc final result.txt", "List"];
d = SmoothHistogram[data, Automatic, "PDF"];
time = 200;

f[x_] := -1/time Log[d, x]
  • 1
    $\begingroup$ Welcome! Please add working code to demonstrate your problem. As it is, we cannot sensibly answer because of lack of information. $\endgroup$
    – Yves Klett
    Sep 4, 2014 at 8:37
  • $\begingroup$ Data = Import["Desktop/kmc final result.txt", "List"]; d = SmoothHistogram[Data, Automatic, "PDF"]; time = 200; f[x_] := -1/time Log[d, x]; $\endgroup$ Sep 4, 2014 at 8:49

2 Answers 2


With some data

data = RandomVariate[NormalDistribution[], 1000]

the SmoothHistogram plot:



is using SmoothKernelDistribution.
You can create the same DataDistribution object using

dist = SmoothKernelDistribution[data]

and then extract the values you see in the plot at a specific single point e.g.

PDF[dist, 0.5]


create a table of values, e.g.:

Table[{x, PDF[dist, x]}, {x, -3.5, 3.5, 0.1}]

or use it within Plot or any other suitable function:

time = 200;
f[x_] := -1/time Log[PDF[dist, x]]
Plot[f[x], {x, -4, 4}]


  • $\begingroup$ So you mean that there is no difference between "smoothkerneldistribution" and "SmoothHistogram"?! $\endgroup$ Sep 4, 2014 at 8:52
  • $\begingroup$ That is how I read the documentation: "SmoothHistogram[data] by default plots the PDF of [data], based on a smooth kernel density estimate. ... The specifications for bandwidth bw and kernel are the same as for SmoothKernelDistribution" $\endgroup$
    – Karsten7
    Sep 4, 2014 at 8:57
  • $\begingroup$ Thanx alot dear friend! $\endgroup$ Sep 4, 2014 at 9:03

As a an alternative, you can also extract the data out of the SmoothHistogram object. This way is a bit dirty and should be done carefully because the "magic index" 1,2,1,3,3,1 could be dependent on Mathematica version and other parameters. This is for v10:

data = RandomVariate[NormalDistribution[], 1000];
dataHist = SmoothHistogram[data]

enter image description here

now directly access the list of plotted points by dataHist[[1, 2, 1, 3, 3, 1]]

dataHist[[1, 2, 1, 3, 3, 1]] // ListLinePlot
{#[[1]], 1/1000*Log[#[[2]]]} & /@dataHist[[1, 2, 1, 3, 3, 1]] // ListLinePlot

enter image description here enter image description here

  • $\begingroup$ one small issue to be aware of , the plot range of SmoothHistogram seems to cut off the very ends of the tails. $\endgroup$
    – george2079
    Sep 5, 2014 at 18:10

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