Haskell plotting library similar to MATLAB

后端 未结 5 1271
天涯浪人
天涯浪人 2021-02-02 09:00

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         


        
相关标签:
5条回答
  • 2021-02-02 09:26

    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)
    
    0 讨论(0)
  • 2021-02-02 09:28

    What about gnuplot?

    For example, plotList from Graphics.Gnuplot.Simple:

    plotList [] [(1, 1), (2, 2), (3, 3)]
    
    0 讨论(0)
  • 2021-02-02 09:31

    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
    
    0 讨论(0)
  • 2021-02-02 09:36

    There is also matplotlib-haskell library (pretty new). It is very expressive yet simple to use.

    Example:

    import Graphics.Matplotlib
    
    plotQuadraticFn :: IO ()
    plotQuadraticFn = onscreen $ plot x y
      where
        x = [-10..10]
        y = fmap (**2) x
    
    0 讨论(0)
  • 2021-02-02 09:46

    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.

    0 讨论(0)
提交回复
热议问题