learn-physics-0.4: src/Physics/Learn/Visual/PlotTools.hs
{-# OPTIONS_GHC -Wall #-}
{- |
Module : Physics.Learn.Visual.PlotTools
Copyright : (c) Scott N. Walck 2011-2014
License : BSD3 (see LICENSE)
Maintainer : Scott N. Walck <walck@lvc.edu>
Stability : experimental
This module contains helping functions for using Gnuplot.
-}
module Physics.Learn.Visual.PlotTools
( label
, postscript
, psFile
, examplePlot1
, examplePlot2
)
where
import Graphics.Gnuplot.Simple
( Attribute(..)
, plotFunc
)
-- | An 'Attribute' with a given label at a given position.
label :: String -> (Double,Double) -> Attribute
label name (x,y)
= Custom "label" [show name ++ " at " ++ show x ++ "," ++ show y]
-- | An 'Attribute' that requests postscript output.
postscript :: Attribute
postscript = Custom "term" ["postscript"]
-- | An 'Attribute' giving the postscript file name.
psFile :: FilePath -> Attribute
psFile file = Custom "output" [show file]
-- | An example of the use of 'label'. See the source code.
examplePlot1 :: IO ()
examplePlot1 = plotFunc [Title "Cosine Wave"
,XLabel "Time (ms)"
,YLabel "Velocity"
,label "Albert Einstein" (2,0.8)
] [0,0.01..10::Double] cos
-- | An example of the use of 'postscript' and 'psFile'. See the source code.
examplePlot2 :: IO ()
examplePlot2 = plotFunc [Title "Cosine Wave"
,XLabel "Time (ms)"
,YLabel "Velocity of Car"
,label "Albert Einstein" (2,0.8)
,postscript
,psFile "post1.ps"
] [0,0.01..10::Double] cos