'Is there a way to overlay Haskell GNUPlot plots on top of each other?

I'm using GNUPlot.Simple for Haskell and am trying to plot 2 charts on top of each other. One is using the filled curve format, one is a normal line. The code I am using is :

plotListsStyle []  [ (( defaultStyle {plotType =  FilledCurves} ) , ( zip3 [1,2,3] [2,3,4] [0,1,2] )), ((PlotStyle {plotType = Lines, lineSpec = CustomStyle [PointSize 0.1] }), (zip [1,2,3] [1,2,3]) )]

They work fine when I do them separately as:

plotListsStyle []  [ (( defaultStyle {plotType =  FilledCurves} ) , ( zip3 [1,2,3] [2,3,4] [0,1,2] ))]

and

plotListsStyle [] [((PlotStyle {plotType = Lines, lineSpec = CustomStyle [PointSize 0.1] }), (zip [1,2,3] [1,2,3]) )]

but not when done together. Is it possible to overlay GNUPlots on top of each other?



Solution 1:[1]

It looks like you just need to trick the type checker by supplying some extra data that GNUPlot doesn't actually need. Try something like:

import Graphics.Gnuplot.Simple

main = do
  plotListsStyle []
    [ ( defaultStyle {plotType =  FilledCurves}
      , zip3 [1::Double,2,3] [2::Double,3,4] [0::Double,1,2] )
    , ( PlotStyle {plotType = Lines, lineSpec = CustomStyle [PointSize 0.1] }
      , zip3 [1::Double,2,3] [1::Double,2,3] (repeat 0))
--                                           ^^^^^^^^^^
--                            Provide this useless extra data
    ]

The problem here is that plotListsStyle takes a list of tuples, and -- as with all Haskll lists -- all the tuples need to be of the same type, so you can't have data of type [(Double,Double,Double)] in one tuple and data of type [(Double,Double)] in another.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 K. A. Buhr