Safe Haskell | None |
---|
This package easily lets you create high quality histogram plots from your data in Haskell. It automatically bins your data using whichever binning strategy you'd like, then plots the data. It uses the gnuplot package to do all the actual graphing, so any options that work for making gnuplot pretty will also work here.
Here's a brief example that should get you going:
import qualified Graphics.Gnuplot.Frame.OptionSet as Opts input = [1,0.2,0.23,0.15,0.1,0.88,0.89,0.33,0.05,0.33,0.45,0.99,0.01,0.01,0.5] simple = do let hist = histogram binSturges input plot "simple.png" hist advanced = do let hist = histogram binSqrt input let opts = Opts.title "I'm a histogram!" $ Opts.yLabel "Why?" $ Opts.xLabel "Because!" $ defOpts hist plotAdv "advanced.eps" opts hist
- histogram :: BinningStrat -> [Double] -> Histogram
- histogramBinSize :: Double -> [Double] -> Histogram
- histogramNumBins :: Int -> [Double] -> Histogram
- binSturges :: BinningStrat
- binDoane :: BinningStrat
- binSqrt :: BinningStrat
- binScott :: BinningStrat
- binFreedmanDiaconis :: BinningStrat
- type PlotOptions = T (T Int Double)
- plot :: String -> Histogram -> IO ExitCode
- plotAdv :: String -> PlotOptions -> Histogram -> IO ExitCode
- defOpts :: Histogram -> PlotOptions
Creating Histograms
histogram :: BinningStrat -> [Double] -> HistogramSource
Creates a histogram that's ready for plotting. Call it with one of the binning strategies that is appropriate to the type of data you have. If you don't know, then try using binSturges.
histogramBinSize :: Double -> [Double] -> HistogramSource
Create a histogram by specifying the exact bin size. You probably don't want to use this function, and should use histogram with an appropriate binning strategy.
histogramNumBins :: Int -> [Double] -> HistogramSource
Create a histogram by specifying the exact number of bins You probably don't want to use this function, and should use histogram with an appropriate binning strategy.
Binning Strategies
binSturges :: BinningStratSource
Sturges' binning strategy is the least computational work, but recommended for only normal data
binDoane :: BinningStratSource
Doane's binning strategy extends Sturges' for non-normal data. It takes a little more time because it must calculate the kurtosis (peakkiness) of the distribution
Using the sqrt of the number of samples is not supported by any theory, but is commonly used by excell and other histogram making software
binScott :: BinningStratSource
Scott's rule is the optimal solution for normal data, but requires more computation than Spurges'
binFreedmanDiaconis :: BinningStratSource
The Freedman-Diaconis rule is less susceptible to outliers than Scott's and is also used on "normalish" data
Graphing Histograms
plot :: String -> Histogram -> IO ExitCodeSource
Plots your histogram using gnuplot. If the filename is empty, then it will open a window and display the histogram on screen. Otherwise, the filetype is automatically determined by the extension. Supported file types are .png, .svg (vector graphics), and .eps (PostScript).
plotAdv :: String -> PlotOptions -> Histogram -> IO ExitCodeSource
Just like plot, except you may specify additional options from the gnuplot library. For example, you could add labels and a title.
defOpts :: Histogram -> PlotOptionsSource
Default plot display parameters