Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell plotting library similar to MATLAB

Is there a Haskell library for drawing plots similar to MATLAB, scilab or matplotlib? They all have very simple interfaces, which work like a state machine:

plot(xs, ys)
show() -- opens window with plot

It would be nice to display plots in a window and to have ability to write them to disk.

like image 380
Trismegistos Avatar asked Jan 26 '12 18:01

Trismegistos


4 Answers

What about gnuplot?

For example, plotList from Graphics.Gnuplot.Simple:

plotList [] [(1, 1), (2, 2), (3, 3)]
like image 75
Yuras Avatar answered Oct 23 '22 09:10

Yuras


From a glance at matplotlib, I don't think the Haskell ecosystem has anything as feature-rich. However, I've been happy with the results produced by the Chart library. There are also bindings to graphviz (that links one of several) and Ubigraph.

Edit: Responding to the request for plotting (x,y) coordinates:

I'm not entirely clear what you want. If you have a function f :: x -> y then just use the plotWindow (or PNG, etc) function:

import Graphics.Rendering.Chart.Simple
main = plotWindow [0,0.1..5::Double] sin

If you have a bunch of points, [(x,y)], then the same code with a lookup into the list, instead of a continuous function like sin, should work fine. See the linked page for many many examples.

like image 20
2 revs Avatar answered Oct 23 '22 08:10

2 revs


There is also the plot package. When used with plot-gtk graphs can be displayed and modified within GHCi. Plots can be written to disk in the formats that Cairo supports.

The Simple interface is similar to gnuplot's:

test_graph2 = do
     plot (ts,[point (ds,es) (Cross,red),line fs blue])
     title "Testing plot package:"
     subtitle "with 1 second of a 15Hz sine wave"
     xlabel "time (s)"
     ylabel "amplitude"
     yrange Linear (-1.25) 1.25
like image 5
vivian Avatar answered Oct 23 '22 07:10

vivian


Try gnuplot. It's cross-language, quite fast at scale, and always a nice thing to know, even if it is old. These instructions should get you a working example:

cabal install gnuplot
sudo apt-get install gnuplot-x11

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)
like image 1
RussellStewart Avatar answered Oct 23 '22 09:10

RussellStewart