LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Blogs > Bits and Pixels
User Name
Password

Notices

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

Quick and dirty plotting with Haskell + Gnuplot

Posted 12-28-2012 at 05:13 PM by hydraMax
Updated 12-28-2012 at 05: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:

Code:
$ ghci
GHCi, version 7.4.1: http://www.haskell.org/ghc/  :? 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:

Code:
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:

http://hackage.haskell.org/packages/...ot-Simple.html
Attached Images
File Type: png image3023.png (29.8 KB, 3 views)
Posted in Uncategorized
Views 1906 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 12:07 AM.

Main Menu

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