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

John Smith badmofo6662004 at yahoo.com
Tue Oct 5 16:48:38 EDT 2010


Thanks.  Exactly what I was trying to do.



________________________________
From: Henning Thielemann <thunderbird at henning-thielemann.de>
To: John Smith <badmofo6662004 at yahoo.com>
Cc: gnuplot at projects.haskell.org
Sent: Tue, October 5, 2010 1:05:52 PM
Subject: Re: [haskell-gnuplot] How to set options for individual lines?

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.



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.haskell.org/pipermail/gnuplot/attachments/20101005/f101c164/attachment.htm 


More information about the Gnuplot mailing list