chart-diagrams example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import System.Environment(getArgs)
import Graphics.Rendering.Chart
import Data.Colour
import Data.Colour.Names
import Data.Default.Class
import Graphics.Rendering.Chart.Backend.Diagrams
import Control.Lens
import Data.Monoid
setLinesBlue :: PlotLines a b -> PlotLines a b
setLinesBlue = plot_lines_style  . line_color .~ opaque blue

chart = toRenderable layout
  where
    am :: Double -> Double
    am x = (sin (x*3.14159/45) + 1) / 2 * (sin (x*3.14159/5))

    sinusoid1 = plot_lines_values .~ [[ (x,(am x)) | x <- [0,(0.5)..400]]]
              $ plot_lines_style  . line_color .~ opaque blue
              $ plot_lines_title .~ "am"
              $ def

    sinusoid2 = plot_points_style .~ filledCircles 2 (opaque red)
              $ plot_points_values .~ [ (x,(am x)) | x <- [0,7..400]]
              $ plot_points_title .~ "am points"
              $ def

    layout = layout_title .~ "Amplitude Modulation"
           $ layout_plots .~ [toPlot sinusoid1,
                              toPlot sinusoid2]
           $ def

main = renderableToFile (FileOptions (800,600) SVG mempty) chart "example1_big.svg"
15:12: Warning: Redundant bracket
Found:
(sin (x * 3.14159 / 45) + 1) / 2 * (sin (x * 3.14159 / 5))
Why not:
(sin (x * 3.14159 / 45) + 1) / 2 * sin (x * 3.14159 / 5)
17:41: Warning: Redundant bracket
Found:
(x, (am x))
Why not:
(x, am x)
17:62: Error: Redundant bracket
Found:
(0.5)
Why not:
0.5
23:41: Warning: Redundant bracket
Found:
(x, (am x))
Why not:
(x, am x)