Hoodlums Message Board › Tip: simple charting from ghci
At this month's hoodlums meetup we wanted to plot some numeric values quickly. We printed the values to newline-separated text file and used the gnuplot utility. (It's a great tool to know).
If you really want to do it in haskell and from the comfort of GHCI, here is the simplest example of the chart package.
To install it, cabal install chart.
main = plotWindow xs ys "x" "series name here"
xs = [1..]::[Double]
ys = [5,10,20,7,3]::[Double]
(Yuck, indentation is lost by this message board!)
For beginners, here's a helper script:
simplePlot ys = plotWindow ([1..]::[Double]) ys "x" "unnamed"
If you save that and :load it into your ghci session, you can generate a simple plot with the following:
simplePlot [3.1, 6.2, 10, 8, 1]
or (revisiting our square-wave generation):
simplePlot $ take 100 $ cycle $ ((replicate 8 1 ++ replicate 8 (-1))::[Double])
That needs some some tweaking to work nicely with Int, Integer and Float. For now, though, if you have a list "myValues" of elements of type Int or Integer, you can do simplePlot $ map fromIntegral myValues
That package has many more powerful rendering options.
Edited by Neil B on May 13, 2011 12:42 AM
|Guy Thomas B.||
Hmm there seem to be some issues with using this from Ubuntu. I think you might need to install the latest version of GHC manually rather than using apt-get. (Cabal is basically refusing to self update and you can't install chart without the latest version apparently).
Macports version of ghc seems to be struggling too...