{-# OPTIONS_GHC -Wall -fno-warn-missing-export-lists #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Graphics.Plotly.Example where
import Control.Monad
import System.Random
import Graphics.Plotly
plotPath :: String -> FilePath
plotPath :: String -> String
plotPath String
name = String
"./plots/" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
name String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
".html"
scatterExample :: IO ()
scatterExample :: IO ()
scatterExample = String -> Script -> IO ()
plot (String -> String
plotPath String
"scatter") Script
scatterPlot
where
scatterPlot :: Script
scatterPlot = [String] -> [[Double]] -> [[Double]] -> PlotConfig -> Script
scatter' [String
"foo", String
"bar"]
[[Double
1, Double
2, Double
3, Double
4], [Double
1, Double
2, Double
3, Double
4]]
[[Double
10, Double
15, Double
13, Double
17], [Double
16, Double
5, Double
11, Double
9]]
(PlotConfig -> Script) -> PlotConfig -> Script
forall a b. (a -> b) -> a -> b
$ PlotConfig
defaultConfig { $sel:lineMode:PlotConfig :: Mode
lineMode = Mode
LinesMarkers }
histExample :: IO ()
histExample :: IO ()
histExample = do
[Double]
x1 <- Int -> IO Double -> IO [Double]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
100 ((Double, Double) -> IO Double
forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO (Double
0, Double
5) ) :: IO [Double]
[Double]
x2 <- Int -> IO Double -> IO [Double]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
100 ((Double, Double) -> IO Double
forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO (Double
0, Double
5) ) :: IO [Double]
[Double]
x3 <- Int -> IO Double -> IO [Double]
forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
100 ((Double, Double) -> IO Double
forall a (m :: * -> *). (Random a, MonadIO m) => (a, a) -> m a
randomRIO (Double
0, Double
5) ) :: IO [Double]
let histPlot :: Script
histPlot = [String] -> [[Double]] -> PlotConfig -> Script
histogram [String
"x1", String
"x2", String
"x3"] [[Double]
x1,[Double]
x2,[Double]
x3]
(PlotConfig -> Script) -> PlotConfig -> Script
forall a b. (a -> b) -> a -> b
$ PlotConfig
defaultConfig {$sel:title':PlotConfig :: String
title' = String
"A Histogram of Random Data"}
String -> Script -> IO ()
plot (String -> String
plotPath String
"hist") Script
histPlot
heatmapExample :: IO ()
heatmapExample :: IO ()
heatmapExample = String -> Script -> IO ()
plot (String -> String
plotPath String
"heatmap") Script
heatPlot
where
heatPlot :: Script
heatPlot = [String] -> [String] -> [[Double]] -> PlotConfig -> Script
heatmap [String
"Monday", String
"Tuesday", String
"Wednesday", String
"Thursday", String
"Friday"]
[String
"Morning", String
"Afternoon", String
"Evening"]
[[Double
1, Double
0, Double
30, Double
50, Double
1], [Double
20, Double
1, Double
60, Double
80, Double
30], [Double
30, Double
60, Double
1, -Double
10, Double
20]]
PlotConfig
defaultConfig
scatter3dExample :: IO ()
scatter3dExample :: IO ()
scatter3dExample = String -> Script -> IO ()
plot (String -> String
plotPath String
"scatter3d") Script
scatter3dPlot
where
scatter3dPlot :: Script
scatter3dPlot = [String]
-> [[Double]] -> [[Double]] -> [[Double]] -> PlotConfig -> Script
scatter3d [String
"point cloud"] [[Double
1, Double
0, Double
30, Double
50, Double
1]]
[[Double
20, Double
1, Double
60, Double
80, Double
30]] [[Double
30, Double
60, Double
1, -Double
10, Double
20]]
(PlotConfig -> Script) -> PlotConfig -> Script
forall a b. (a -> b) -> a -> b
$ PlotConfig
defaultConfig {$sel:lineMode:PlotConfig :: Mode
lineMode = Mode
Markers}
surfaceExample :: IO ()
surfaceExample :: IO ()
surfaceExample = String -> Script -> IO ()
plot (String -> String
plotPath String
"surface1") Script
surfPlot''
IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Script -> IO ()
plot (String -> String
plotPath String
"surface2") Script
surfPlot'
where
xx :: [Double]
xx = (Double -> Double) -> [Double] -> [Double]
forall a b. (a -> b) -> [a] -> [b]
map ((Double -> Double -> Double
forall a. Num a => a -> a -> a
*Double
10) (Double -> Double) -> (Double -> Double) -> Double -> Double
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Double -> Double
forall a. Num a => a -> a -> a
subtract Double
5) [Double
0 .. Double
14]
yy :: [Double]
yy = [Double
2,Double
4,Double
6,Double
8,Double
10,Double
12]
zz :: [[Double]]
zz = [ [Double
8.83,Double
8.89,Double
8.81,Double
8.87,Double
8.9,Double
8.87]
, [Double
8.89,Double
8.94,Double
8.85,Double
8.94,Double
8.96,Double
8.92]
, [Double
8.84,Double
8.9,Double
8.82,Double
8.92,Double
8.93,Double
8.91]
, [Double
8.79,Double
8.85,Double
8.79,Double
8.9,Double
8.94,Double
8.92]
, [Double
8.79,Double
8.88,Double
8.81,Double
8.9,Double
8.95,Double
8.92]
, [Double
8.8,Double
8.82,Double
8.78,Double
8.91,Double
8.94,Double
8.92]
, [Double
8.75,Double
8.78,Double
8.77,Double
8.91,Double
8.95,Double
8.92]
, [Double
8.8,Double
8.8,Double
8.77,Double
8.91,Double
8.95,Double
8.94]
, [Double
8.74,Double
8.81,Double
8.76,Double
8.93,Double
8.98,Double
8.99]
, [Double
8.89,Double
8.99,Double
8.92,Double
9.1,Double
9.13,Double
9.11]
, [Double
8.97,Double
8.97,Double
8.91,Double
9.09,Double
9.11,Double
9.11]
, [Double
9.04,Double
9.08,Double
9.05,Double
9.25,Double
9.28,Double
9.27]
, [Double
9,Double
9.01,Double
9,Double
9.2,Double
9.23,Double
9.2]
, [Double
8.99,Double
8.99,Double
8.98,Double
9.18,Double
9.2,Double
9.19]
, [Double
8.93,Double
8.97,Double
8.97,Double
9.18,Double
9.2,Double
9.18] ]
surfPlot'' :: Script
surfPlot'' = [String] -> [[[Double]]] -> PlotConfig -> Script
surface'' [String
"surface"] [[[Double]]
zz] PlotConfig
defaultConfig
surfPlot' :: Script
surfPlot' = [String]
-> [Double] -> [Double] -> [[[Double]]] -> PlotConfig -> Script
surface' [String
"surface"] [Double]
xx [Double]
yy [[[Double]]
zz] PlotConfig
defaultConfig
parcoordsExample :: IO ()
parcoordsExample :: IO ()
parcoordsExample = String -> Script -> IO ()
plot (String -> String
plotPath String
"parcoords1") Script
parPlot'
IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> String -> Script -> IO ()
plot (String -> String
plotPath String
"parcoords2") Script
parPlot
where
as :: [Double]
as = [Double
1,Double
2,Double
3,Double
5]
bs :: [Double]
bs = [Double
3.1,Double
1.5,Double
4.5,Double
9.3]
cs :: [Double]
cs = [Double
2,Double
4,Double
6,Double
8]
ds :: [Double]
ds = [-Double
3,-Double
5,-Double
10,-Double
7]
c' :: [Double]
c' = [Double
0.0,Double
1.0,Double
0.0,Double
0.0,Double
1.0,Double
1.0,Double
0.0,Double
1.0]
parPlot' :: Script
parPlot' = [String] -> [[[Double]]] -> PlotConfig -> Script
parcoord'' [String
"A", String
"B", String
"C", String
"D"] [[[Double]
as,[Double]
bs,[Double]
cs,[Double]
ds], [[Double]
bs,[Double]
ds,[Double]
as,[Double]
cs]]
(PlotConfig -> Script) -> PlotConfig -> Script
forall a b. (a -> b) -> a -> b
$ PlotConfig
defaultConfig {$sel:width:PlotConfig :: Int
width = Int
1500, $sel:height:PlotConfig :: Int
height = Int
600}
parPlot :: Script
parPlot = [Double] -> [String] -> [[[Double]]] -> PlotConfig -> Script
parcoord' [Double]
c' [String
"A", String
"B", String
"C", String
"D"] [[[Double]
as,[Double]
bs,[Double]
cs,[Double]
ds], [[Double]
bs,[Double]
ds,[Double]
as,[Double]
cs]]
(PlotConfig -> Script) -> PlotConfig -> Script
forall a b. (a -> b) -> a -> b
$ PlotConfig
defaultConfig {$sel:width:PlotConfig :: Int
width = Int
1500, $sel:height:PlotConfig :: Int
height = Int
600, $sel:colorScale:PlotConfig :: ColorScale
colorScale = ColorScale
Discrete}