Share your knowledge at the LQ Wiki.
Go Back > Blogs > Bits and Pixels
User Name


Concerning free software, programming, and whatever else I find interesting. Also the blog for my Web site,
Rate this Entry

Quick and dirty plotting with Haskell + Gnuplot

Posted 12-28-2012 at 06:13 PM by hydraMax
Updated 12-28-2012 at 06:17 PM by hydraMax
Tags haskell

Assuming you are a Haskeller, you can get a simply x-y plot up very quickly with the gnuplot interface module. This is useful for getting a rough graphical view of some function. Simply...

1. install Gnuplot (through your package manager)
2. cabal install gnuplot
3. use ghci:

$ ghci
GHCi, version 7.4.1:  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
h> import Graphics.Gnuplot.Simple
h> plotFunc [] (linearScale 1000 (-20,20)) (\x -> sin x / x)
Read the lambda as f(x) = sin (x) / x. You can change the x-range from (-20,20) to whatever you prefer. A Gnuplot window will appear, containing the graph.

If you want a plot of a points list:

plotList [] [(2,10),(3,15),(4,14),(5,19)]
In both cases the empty list just means use the default plot attributes. Of course, much can be changed from the simple example I gave. See the documentation of the Simple gnuplot module:
Attached Images
File Type: png image3023.png (29.8 KB, 3 views)
Posted in Uncategorized
Views 3753 Comments 0
« Prev     Main     Next »
Total Comments 0




All times are GMT -5. The time now is 12:44 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration