[haskell-gnuplot] How to set options for individual lines?

Henning Thielemann thunderbird at henning-thielemann.de
Tue Oct 5 13:05:52 EDT 2010


John Smith wrote:
> I'm using the advanced interface like the demo shows.  Here's the 
> function I'm using to plot functions:
> 
> plot1VarFunctions :: [(Double -> Double)] -> (Double,Double) 
> -> (Double,Double) -> Frame.T (Graph2D.T Double Double)
> plot1VarFunctions functionList domain range =
>    let lineSpec =
>           Graph2D.lineSpec $
>           LineSpec.deflt
>        frameOpts =
>           Opts.xRange2d domain $
>           Opts.yRange2d range
>           Opts.deflt
>    in Frame.cons frameOpts $ fmap lineSpec $
>       Plot2D.functions Graph2D.lines
>       (linearScale 100 domain) functionList
> 
> I would like to be able to pass it a list of tuples (or maybe a list of 
> a custom type) that holds functions with their corresponding names, but 
> I can't figure out how to change names individually. Setting 
> LineSpec."..." in lineSpec changes the names of all the lines.

First I assumed, my gnuplot wrapper had a bug, but now I understand.
I think, what you need is:

plot1VarFunctions ::
    [(String, Double -> Double)] ->
    (Double,Double) -> (Double,Double) ->
    Frame.T (Graph2D.T Double Double)
plot1VarFunctions functionList domain range =
    let lineSpec name =
           Graph2D.lineSpec $
           LineSpec.title name $
           LineSpec.deflt
        frameOpts =
           Opts.xRange2d domain $
           Opts.yRange2d range
           Opts.deflt
    in Frame.cons frameOpts $ mconcat $
       map (\(name,f) ->
          fmap (lineSpec name) $
          Plot2D.function Graph2D.lines (linearScale 100 domain) f) $
       functionList


Demo> Plot.plot X11.cons $ plot1VarFunctions [("sin",sin), ("cos",cos)] 
(-10,10) (-1,1)

If you need individual specifications for the plotted functions, you 
cannot use 'Plot2D.functions', but you need multiple calls to 
'Plot2D.function'. You can assemble them using the "mconcat" function 
from Data.Monoid.



More information about the Gnuplot mailing list