Skip to content

Commit 236a563

Browse files
muehlmuehl
authored andcommitted
Add histogram docs
1 parent 87e677e commit 236a563

File tree

11 files changed

+104
-87
lines changed

11 files changed

+104
-87
lines changed

FSharp.Plotly.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D
3030
ProjectSection(SolutionItems) = preProject
3131
docs\content\2d-histograms.fsx = docs\content\2d-histograms.fsx
3232
docs\content\3d-line-plots.fsx = docs\content\3d-line-plots.fsx
33+
docs\content\3d-mesh-plots.fsx = docs\content\3d-mesh-plots.fsx
3334
docs\content\3d-scatter-plots.fsx = docs\content\3d-scatter-plots.fsx
3435
docs\content\3d-surface-plots.fsx = docs\content\3d-surface-plots.fsx
3536
docs\content\area-plots.fsx = docs\content\area-plots.fsx

docs/content/2d-histograms.fsx

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,50 @@
77
88
*Summary:* This example shows how to create a bi-dimensional histogram of two data samples in F#.
99
10-
A Histogram2d chart can be created using the `Chart.Histogram2d` functions.
10+
A Histogram2d chart can be created using the `Chart.Histogram2d` or `Chart.Histogram2dContour` functions.
1111
*)
1212

1313
open FSharp.Plotly
14-
14+
15+
// generate random normaly distributed data
16+
let normal (rnd:System.Random) mu tau =
17+
let mutable v1 = 2.0 * rnd.NextDouble() - 1.0
18+
let mutable v2 = 2.0 * rnd.NextDouble() - 1.0
19+
let mutable r = v1 * v1 + v2 * v2
20+
while (r >= 1.0 || r = 0.0) do
21+
v1 <- 2.0 * rnd.NextDouble() - 1.0
22+
v2 <- 2.0 * rnd.NextDouble() - 1.0
23+
r <- v1 * v1 + v2 * v2
24+
let fac = sqrt(-2.0*(log r)/r)
25+
(tau * v1 * fac + mu)
26+
27+
28+
1529
let rnd = System.Random()
16-
let x' = [for i=0 to 500 do yield rnd.NextDouble() ]
17-
let y' = [for i=0 to 500 do yield rnd.NextDouble() ]
30+
let n = 2000
31+
let a = -1.
32+
let b = 1.2
33+
let step i = a + ((b - a) / float (n - 1)) * float i
34+
35+
// generate data disturbed in x and y direction
36+
let x = Array.init n (fun i -> ((step i)**3.) + (0.3 * (normal (rnd) 0. 2.) ))
37+
let y = Array.init n (fun i -> ((step i)**6.) + (0.3 * (normal (rnd) 0. 2.) ))
38+
39+
(*** define-output:Histogram2dContour1 ***)
40+
[
41+
Chart.Histogram2dContour (x,y,Line=Line.init(Width=0))
42+
Chart.Point(x,y,Opacity=0.3)
43+
]
44+
|> Chart.Combine
45+
(*** include-it:Histogram2dContour1 ***)
46+
47+
48+
(*** define-output:Histogram2d1 ***)
49+
Chart.Histogram2d (x,y)
50+
(*** include-it:Histogram2d1 ***)
51+
52+
53+
54+
1855

19-
(*** define-output:histo1 ***)
20-
[for i=0 to 500 do yield rnd.NextDouble(),rnd.NextDouble() ]
21-
|> Chart.Histogram2d
22-
|> Chart.withSize(500.,500.)
23-
(*** include-it:histo1 ***)
56+

docs/content/3d-mesh-plots.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Trace3d.initMesh3d
5252
mesh3d?y <- b
5353
mesh3d?z <- c
5454
mesh3d?flatshading <- true
55-
//mesh3d?contour <- cont
55+
mesh3d?contour <- Contours.initXyz(Show=true)
5656
mesh3d
5757
)
5858
|> GenericChart.ofTraceObject

docs/content/3d-surface-plots.fsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ let a = Array.init 50 (fun _ -> rnd.NextDouble())
4141
let b = Array.init 50 (fun _ -> rnd.NextDouble())
4242
let c = Array.init 50 (fun _ -> rnd.NextDouble())
4343

44-
//let contours =
45-
4644

4745
(*** define-output:contour1 ***)
4846
z
@@ -58,7 +56,8 @@ let z' = [
5856
[1.;2.;];
5957
] // column (length y)
6058

61-
//Chart.Surface(z',x',y',Opacity=0.,Contours=Contours. init(Contours.styleXyz(Show=true)))
62-
//|> Chart.Show
59+
(*** define-output:contour2 ***)
60+
Chart.Surface(z',x',y',Opacity=0.5,Contours=Contours.initXyz(Show=true))
61+
(*** define-output:contour2 ***)
6362

6463

docs/content/histograms.fsx

Lines changed: 11 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,68 +3,23 @@
33
#r "../../bin/FSharp.Plotly.dll"
44

55
(**
6-
# FSharp.Plotly: Pie and Doughnut Charts
6+
# FSharp.Plotly: Histogram2d
77
8-
*Summary:* This example shows how to create pie and doughnut charts in F#.
8+
*Summary:* This example shows how to create a one-dimensional histogram of a data samples in F#.
99
10-
A pie or a doughnut chart can be created using the `Chart.Pie` and `Chart.Doughnut` functions.
11-
When creating pie or doughnut charts, it is usually desirable to provide both labels and
12-
values.
10+
A histogram consisting of rectangles whose area is proportional to the frequency of a variable and whose width is equal to the class interval.
11+
The histogram chart represents the distribution of numerical data and can be created using the `Chart.Histogram`.
1312
*)
1413

1514
open FSharp.Plotly
1615

17-
18-
let normal (rnd:System.Random) mu tau =
19-
let mutable v1 = 2.0 * rnd.NextDouble() - 1.0
20-
let mutable v2 = 2.0 * rnd.NextDouble() - 1.0
21-
let mutable r = v1 * v1 + v2 * v2
22-
while (r >= 1.0 || r = 0.0) do
23-
v1 <- 2.0 * rnd.NextDouble() - 1.0
24-
v2 <- 2.0 * rnd.NextDouble() - 1.0
25-
r <- v1 * v1 + v2 * v2
26-
let fac = sqrt(-2.0*(log r)/r)
27-
(tau * v1 * fac + mu)
28-
2916
let rnd = System.Random()
30-
let sampleNormal () =
31-
normal (rnd) 0. 2.
32-
33-
let n = 2000
34-
let a = -1.
35-
let b = 1.2
36-
let step i = a + ((b - a) / float (n - 1)) * float i
37-
38-
let x = Array.init n (fun i -> ((step i)**3.) + (0.3 * sampleNormal () ))
39-
let y = Array.init n (fun i -> ((step i)**6.) + (0.3 * sampleNormal () ))
40-
41-
42-
let colorScale = StyleParam.Colorscale.Custom [(0.0,"white");(1.0,"red")]
43-
44-
(*** define-output:Histogram2dContour1 ***)
45-
[
46-
Chart.Histogram2dContour (x,y,Colorscale=colorScale,Line=Line.init(Width=0))
47-
Chart.Point(x,y,Opacity=0.3)
48-
]
49-
|> Chart.Combine
50-
(*** include-it:Histogram2dContour1 ***)
17+
let x = [for i=0 to 500 do yield rnd.NextDouble() ]
18+
19+
(*** define-output:histo1 ***)
20+
x
21+
|> Chart.Histogram
22+
|> Chart.withSize(500.,500.)
23+
//(*** include-it:histo1 ***)
5124
|> Chart.Show
5225

53-
54-
(*** define-output:Histogram1 ***)
55-
[
56-
//var layout = {barmode: "overlay"};
57-
Chart.Histogram x
58-
Chart.Histogram y
59-
]
60-
|> Chart.Combine
61-
(*** include-it:Histogram1 ***)
62-
|> Chart.Show
63-
64-
65-
(*** define-output:Histogram2d1 ***)
66-
Chart.Histogram2d (x,y,Colorscale=colorScale)
67-
(*** include-it:Histogram2d1 ***)
68-
|> Chart.Show
69-
70-

docs/content/polar-charts.fsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,4 @@ let t = [0; 45; 90; 135; 200; 320; 184;]
2929
]
3030
|> Chart.Combine
3131
(*** include-it:polar1 ***)
32-
|> Chart.Show
33-
3432

docs/content/windrose-charts.fsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ let r''' = [20.0; 7.5; 15.0; 22.5; 2.5; 2.5; 12.5; 22.5]
2020

2121
let t = ["North"; "N-E"; "East"; "S-E"; "South"; "S-W"; "West"; "N-W"]
2222

23-
(*** define-output:polar1 ***)
23+
(*** define-output:windrose1 ***)
2424
[
2525
Chart.WindRose (r ,t,Name="11-14 m/s")
2626
Chart.WindRose (r' ,t,Name="8-11 m/s")
2727
Chart.WindRose (r'' ,t,Name="5-8 m/s")
2828
Chart.WindRose (r''',t,Name="< 5 m/s")
2929
]
3030
|> Chart.Combine
31-
(*** include-it:polar1 ***)
32-
|> Chart.Show
31+
(*** include-it:windrose1 ***)
32+
3333

3434

docs/tools/templates/template.cshtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
<li><a href="@Root/bubble-charts.html">Bubble Charts</a></li>
5050
<li><a href="@Root/contour-plots.html">Contour Plots</a></li>
5151
<li><a href="@Root/heatmaps.html">Heatmaps</a></li>
52-
@*<li><a href="@Root/histograms.html">Histograms</a></li>
53-
<li><a href="@Root/2d-histograms.html">2D Histograms</a></li>*@
52+
<li><a href="@Root/histograms.html">Histograms</a></li>
53+
<li><a href="@Root/2d-histograms.html">2D Histograms</a></li>
5454
<li><a href="@Root/line-scatter-plots.html">Line and Scatter Plots</a></li>
5555
<li><a href="@Root/pie-daughnut-charts.html">Pie and Doughnut Charts</a></li>
5656
<li><a href="@Root/polar-charts.html">Polar Charts</a></li>
@@ -60,6 +60,7 @@
6060
<li><a href="@Root/3d-scatter-plots.html">3D Scatter Plots</a></li>
6161
<li><a href="@Root/3d-line-plots.html">3D Line Plots</a></li>
6262
<li><a href="@Root/3d-surface-plots.html">3D Surface Plots</a></li>
63+
<li><a href="@Root/3d-mesh-plots.html">3D MEsh Plots</a></li>
6364
<li class="nav-header">Plotly WPF</li>
6465
<li><a href="@Root/plotly-wpf.html">Using Plotly PopUp window</a></li>
6566

src/FSharp.Plotly/Chart.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ type Chart =
387387
|> GenericChart.ofTraceObject
388388

389389
/// Computes the bi-dimensional histogram of two data samples and auto-determines the bin size.
390-
static member Histogram2d(x,y,?Z,?Name,?Colorscale,?Showscale,?zSmooth,?Colorbar,?zAuto,?zMin,?zMax,?nBinsx,?nBinsy,?Xbins,?Ybins,?HistNorm,?HistFunc) =
390+
static member Histogram2d(x,y,?Z,?Name,?Showlegend,?Colorscale,?Showscale,?zSmooth,?Colorbar,?zAuto,?zMin,?zMax,?nBinsx,?nBinsy,?Xbins,?Ybins,?HistNorm,?HistFunc) =
391391
Trace.initHistogram2d (
392392
TraceStyle.Histogram2d (X=x, Y=y,? Z=Z,
393393
?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar) )

src/FSharp.Plotly/Contours.fs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,32 @@ type Contours () =
9999
)
100100

101101

102+
// Initialized x-y-z-Contours with the same properties
103+
static member initXyz
104+
(
105+
?Show ,
106+
//?Project ,
107+
?Color,
108+
?Usecolor ,
109+
?Width ,
110+
?Highlight ,
111+
?Highlightcolor ,
112+
?Highlightwidth
113+
114+
) =
115+
Contours ()
116+
|> Contours.styleXyz
117+
(
118+
?Show=Show ,
119+
//?Project ,
120+
?Color=Color ,
121+
?Usecolor=Usecolor ,
122+
?Width=Width ,
123+
?Highlight=Highlight ,
124+
?Highlightcolor=Highlightcolor,
125+
?Highlightwidth=Highlightwidth
126+
)
127+
102128
// Applies the styles to Contours()
103129
//[<CompiledName("styleXyz")>]
104130
static member styleXyz

0 commit comments

Comments
 (0)