Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
Try First@Cases[SmoothHistogram[something ...], Line[a___] :> a, Infinity]! This is the data now use Export on this data and for help with the possible export file format check the docs. –  PlatoManiac Nov 29 '13 at 12:50
add comment

1 Answer

up vote 4 down vote accepted

There are two methods:

  1. Extract the data directly from the SmoothHistogram plot:

    r = RandomReal[NormalDistribution[], 1000];
    plot = SmoothHistogram[r]
    

    enter image description here

    pts1 = Join @@ Cases[plot, Line[p__] :> p, ∞]
    
    {{-4.10173, 0.}, {-4.10173, 0.}, {-4.09273, 0.000372864}, ... }
    
  2. Use regular HistogramList with the subsequent smoothing

    pts2 = 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 and 12*1 = 12 is the standard deviation in units 0.02.

Verification:

ListLinePlot[{pts1, pts2}]

enter image description here

Then you can Export pts1 or pts2.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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