Last active
February 1, 2016 09:09
-
-
Save BartMassey/9c4ad1d06e2a004769bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Copyright © 2016 Bart Massey | |
-- Chart Histogram demo | |
import Control.Lens | |
import Data.Default.Class | |
import Graphics.Rendering.Chart | |
import Graphics.Rendering.Chart.Backend.Cairo | |
pdfRender :: String -> Renderable a -> IO () | |
pdfRender name r = do | |
_ <- renderableToFile (fo_format .~ PDF $ def) name r | |
return () | |
demoData :: [Double] | |
demoData = concat $ zipWith replicate [5, 4, 3, 7] [0..3] | |
plotDemoHist :: Renderable (LayoutPick Double Int Int) | |
plotDemoHist = do | |
let histPlot = | |
histToPlot $ | |
plot_hist_values .~ demoData $ | |
plot_hist_bins .~ 4 $ | |
defaultPlotHist | |
let histLayout = | |
layout_x_axis .~ (laxis_title .~ "value" $ def) $ | |
layout_y_axis .~ (laxis_title .~ "frequency" $ def) $ | |
layout_plots .~ [histPlot] $ | |
def | |
layoutToRenderable histLayout | |
main :: IO () | |
main = | |
pdfRender "demo-hist.pdf" plotDemoHist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment