This is a jupyter notebook version of the original $\lambda$plot page using the awesome ihaskell kernel.
:ext FlexibleContexts
import Numeric.LinearAlgebra
import Graphics.SVG
import IHaskell.Display
data RawSVG = RawSVG String
instance IHaskellDisplay RawSVG where
display (RawSVG s) = return $ -- Display [html s]
Display [html $ "<div style=\"width:600px\">"++ s ++ "</div>"]
lplot = RawSVG . hPlot
x = linspace 100 (0,2*pi)
lplot
[ plot x (sin x) "blue" 1 "sin x"
, plot x (cos (2*x)) "brown" 3 "cos(2x)"
]
x = vector [1,3,4,7,16]
lplot [ Title "SAMPLES", Labels "x" "sqrt(x)", PlotSize 700 400
, MarginX 0.05, MinY 0, DeltaX 1, DeltaY 0.5, DecY 1
, GridSty "none", LegendPos 0.1 0.8
, plotMark x (sqrt x) "green" 1 circles "red" 4 "sqrt"
, textAt 8 2.5 "Hi!"
]
let t = linspace 100 (0,4*pi) in lplot
[ Title "spiral", Labels "x" "y", VisibleSize 400 400
, MinX (-5), MaxX 5, MinY (-5), MaxY 5
, plot (0.3*t*cos t) (0.3*t*sin t) "red" 1 ""
]
:opt no-lint
import Util.Statistics(histogram)
plot4 = lplot
[ LegendPos 0.7 0.9, Labels "x" "P(x)", Title "histogram"
, MinY 0, MarginX 0.05
, plotHistogram hist "pink" "red" 1 "empirical"
, plot x teor dashblue 2 "theoretical"
]
where
samples = randomVector 666 Gaussian 200
hist = histogram 20 (-4,4) samples
teor = 1/sqrt(2*pi)/1*exp(-0.5*((x-0)/1)**2)
x = linspace 100 (-4,4)
dashblue = "blue;stroke-dasharray:2"
plot4
:opt lint
plot5 = lplot
[ MinY 0, LegendPos 0.1 0.8
, Plots [ fromY 0 (x,y1) ~> (plotFill "lightgreen" "green" 2, "good ")
, fromY 0 (x,y2) ~> (plotFill "pink" "red" 2, "bad")
]
]
where
x = linspace 20 (0,10)
y1 = 3*x + randomVector 666 Gaussian 20
y2 = 2*x + randomVector 777 Gaussian 20
plot5
let
f x = 1/sqrt(2*pi)/1*exp(-0.5*((x-0)/1)**2)
x = linspace 100 (-4,4)
x' = linspace 20 (0.5,2::Double)
in lplot
[ MinY 0
, Plots [ fromY 0 (x',f x') ~> (plotFill "skyblue" "none" 1, "")
, (x, f x) ~> (plotColor "black" 2, "")
]
]
:ext ViewPatterns
let
c1 = gaussianSample 666 30 (vector [3,3]) (matrix 2 [1, 0.8, 0.8,1])
c2 = gaussianSample 777 20 (vector [-3,-3]) (matrix 2 [1,-0.8, -0.8,1])
c3 = gaussianSample 888 20 (vector [-2,2]) (matrix 2 [0.5,0, 0,0.5])
scatter (toColumns -> [x, y]) = plotFullMark x y "none" 1
in lplot
[ scatter c1 circles "green" 4 "black" 1 "good "
, scatter c2 squares "red" 4 "black" 1 "bad"
, scatter c3 diamonds "cyan" 5 "blue" 1 "?"
, MarginX 0.05, Title "scatterplot", PlotSize 600 500
]
let
x = vector [1,3,4,7,16]
ϵ = vector [0.2,0.1,0.3,0.2,0.2]
in lplot
[ MarginX 0.1, MarginY 0.1
, plotErrorMark x (sqrt x) ϵ "orange" 1 circles "green" 3 "blue" 5 "sqrt"
]
let
x = [1,2,3,4]
y = [3,6,5,7]
samples = toColumns
$ gaussianSample 666 100 (vector y) (diagl [0.1,0.5,1,0.5])
in lplot
[ MarginX 0.1, MarginY 0.1, DeltaX 20
, MinX 0.1, MaxX 4.9, MinY 0, MaxY 10
, boxPlot x y samples "orange" 2 "test"
]