My program produces a large data set, which is distributed by some unknown function. I've used SmoothHistogram
to visualise it crudely as a probability distribution function, but now I want to export the plot data from SmoothHistogram
- is there a way for me to retrieve just the line SmoothHistogram
plots, so I can analyse it in an external program?
Answer
There are two methods:
Extract the data directly from the
SmoothHistogram
plot:r = RandomReal[NormalDistribution[], 1000];
plot = SmoothHistogram[r]pts1 = Join @@ Cases[plot, Line[p__] :> p, ∞]
{{-4.10173, 0.}, {-4.10173, 0.}, {-4.09273, 0.000372864}, ... }
Use regular
HistogramList
with the subsequent smoothingpts2 = Transpose@{(Most[#] + Rest[#])/2,
GaussianFilter[#2, 12 {3, 1}, Padding -> 0.0]} & @@
HistogramList[r, {-3.5, 3.5, 0.02}, "PDF"];Here
12*3 = 36
is the radius of Gaussian smoothing and12*1 = 12
is the standard deviation in units0.02
.
Verification:
ListLinePlot[{pts1, pts2}]
Then you can Export
pts1
or pts2
.
Comments
Post a Comment