Skip to content

Commit 15bcdfe

Browse files
committed
Doc: Histograms2d
1 parent d670066 commit 15bcdfe

File tree

10 files changed

+187
-28
lines changed

10 files changed

+187
-28
lines changed

FSharp.Plotly.sln

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "content", "content", "{8E6D
3333
docs\content\bar-charts.fsx = docs\content\bar-charts.fsx
3434
docs\content\box-plots.fsx = docs\content\box-plots.fsx
3535
docs\content\bubble-charts.fsx = docs\content\bubble-charts.fsx
36+
docs\content\contour-plots.fsx = docs\content\contour-plots.fsx
3637
docs\content\heatmaps.fsx = docs\content\heatmaps.fsx
38+
docs\content\histograms.fsx = docs\content\histograms.fsx
3739
docs\content\index.fsx = docs\content\index.fsx
3840
docs\content\line-scatter-plots.fsx = docs\content\line-scatter-plots.fsx
3941
docs\content\pie-daughnut-charts.fsx = docs\content\pie-daughnut-charts.fsx
42+
docs\content\polar-charts.fsx = docs\content\polar-charts.fsx
43+
docs\content\range-plots.fsx = docs\content\range-plots.fsx
4044
EndProjectSection
4145
EndProject
4246
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{ED8079DD-2B06-4030-9F0F-DC548F98E1C4}"

docs/content/2d-histograms.fsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ let x' = [for i=0 to 500 do yield rnd.NextDouble() ]
1717
let y' = [for i=0 to 500 do yield rnd.NextDouble() ]
1818

1919
(*** define-output:histo1 ***)
20-
Chart.Histogram2d(x',y')
20+
[for i=0 to 500 do yield rnd.NextDouble(),rnd.NextDouble() ]
21+
|> Chart.Histogram2d
2122
|> Chart.withSize(500.,500.)
2223
(*** include-it:histo1 ***)

docs/content/contour-plots.fsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(*** hide ***)
2+
#r "../../bin/Newtonsoft.Json.dll"
3+
#r "../../bin/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Pie and Doughnut Charts
7+
8+
*Summary:* This example shows how to create pie and doughnut charts in F#.
9+
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.
13+
*)
14+
15+
open FSharp.Plotly
16+
17+
let values = [19; 26; 55;]
18+
let labels = ["Residential"; "Non-Residential"; "Utility"]
19+
20+
(*** define-output:pie1 ***)
21+
Chart.Pie(values,labels)
22+
(*** include-it:pie1 ***)
23+
24+
(*** define-output:doughnut1 ***)
25+
Chart.Doughnut(values,labels,hole=0.3)
26+
(*** include-it:doughnut1 ***)

docs/content/histograms.fsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(*** hide ***)
2+
#r "../../bin/Newtonsoft.Json.dll"
3+
#r "../../bin/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Pie and Doughnut Charts
7+
8+
*Summary:* This example shows how to create pie and doughnut charts in F#.
9+
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.
13+
*)
14+
15+
open FSharp.Plotly
16+
17+
let values = [19; 26; 55;]
18+
let labels = ["Residential"; "Non-Residential"; "Utility"]
19+
20+
(*** define-output:pie1 ***)
21+
Chart.Pie(values,labels)
22+
(*** include-it:pie1 ***)
23+
24+
(*** define-output:doughnut1 ***)
25+
Chart.Doughnut(values,labels,hole=0.3)
26+
(*** include-it:doughnut1 ***)

docs/content/polar-charts.fsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(*** hide ***)
2+
#r "../../bin/Newtonsoft.Json.dll"
3+
#r "../../bin/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Pie and Doughnut Charts
7+
8+
*Summary:* This example shows how to create pie and doughnut charts in F#.
9+
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.
13+
*)
14+
15+
open FSharp.Plotly
16+
17+
let values = [19; 26; 55;]
18+
let labels = ["Residential"; "Non-Residential"; "Utility"]
19+
20+
(*** define-output:pie1 ***)
21+
Chart.Pie(values,labels)
22+
(*** include-it:pie1 ***)
23+
24+
(*** define-output:doughnut1 ***)
25+
Chart.Doughnut(values,labels,hole=0.3)
26+
(*** include-it:doughnut1 ***)

docs/content/range-plots.fsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(*** hide ***)
2+
#r "../../bin/Newtonsoft.Json.dll"
3+
#r "../../bin/FSharp.Plotly.dll"
4+
5+
(**
6+
# FSharp.Plotly: Pie and Doughnut Charts
7+
8+
*Summary:* This example shows how to create pie and doughnut charts in F#.
9+
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.
13+
*)
14+
15+
open FSharp.Plotly
16+
17+
let values = [19; 26; 55;]
18+
let labels = ["Residential"; "Non-Residential"; "Utility"]
19+
20+
(*** define-output:pie1 ***)
21+
Chart.Pie(values,labels)
22+
(*** include-it:pie1 ***)
23+
24+
(*** define-output:doughnut1 ***)
25+
Chart.Doughnut(values,labels,hole=0.3)
26+
(*** include-it:doughnut1 ***)

docs/tools/templates/template.cshtml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,15 @@
3636
@RenderBody()
3737
</div>
3838
<div class="span3">
39-
<img src="@Root/img/logo.png" alt="F# Project" style="width:150px;margin:10px" />
39+
<img src="@Root/img/logo.png" alt="FSharp.Plotly" style="width:150px;margin:10px" />
4040
<ul class="nav nav-list" id="menu" style="margin-top: 20px;">
4141
<li class="nav-header">@Properties["project-name"]</li>
4242
<li><a href="@Root/index.html">Home page</a></li>
4343
<li class="divider"></li>
44-
<li><a href="@Properties["project-nuget"]">Get Library via NuGet</a></li>
45-
<li><a href="@Properties["project-github"]">Source Code on GitHub</a></li>
46-
<li><a href="@Root/license.html">License</a></li>
47-
<li><a href="@Root/release-notes.html">Release Notes</a></li>
4844

4945
<li class="nav-header">Plotly Charts</li>
5046
<li><a href="@Root/line-scatter-plots.html">Line and Scatter Plots</a></li>
47+
<li><a href="@Root/range-plots.html">Line and Scatter Plots</a></li>
5148
<li><a href="@Root/pie-daughnut-charts.html">Pie and Doughnut Charts</a></li>
5249
<li><a href="@Root/bar-charts.html">Bar</a></li>
5350
<li><a href="@Root/box-plots.html">Box Plots</a></li>
@@ -58,12 +55,12 @@
5855
<li><a href="@Root/histograms.html">Histograms</a></li>
5956
<li><a href="@Root/2d-histograms.html">2D Histograms</a></li>
6057
<li><a href="@Root/polar-charts.html">Polar Charts</a></li>
61-
<li><a href="@Root/time-series.html">Time Series</a></li>
62-
<li><a href="@Root/multiple-chart-types.html">Multiple Chart Types</a></li>
63-
<li><a href="@Root/log-plots.html">Log Plots</a></li>
58+
59+
<li class="nav-header">Plotly 3d-Charts</li>
6460
<li><a href="@Root/3d-scatter-plots.html">3D Scatter Plots</a></li>
65-
<li><a href="@Root/3d-surface-plots.html">3D Surface Plots</a></li>
6661
<li><a href="@Root/3d-line-plots.html">3D Line Plots</a></li>
62+
<li><a href="@Root/3d-surface-plots.html">3D Surface Plots</a></li>
63+
6764

6865

6966
<li class="nav-header">Documentation</li>

src/FSharp.Plotly/Chart.fs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -228,20 +228,29 @@ type Chart =
228228
)
229229
GenericChart.Chart (trace,None)
230230

231-
/// Compute the bi-dimensional histogram of two data samples.
232-
static member Histogram2d(x,y) =
233-
//let marker = Marker() |> Helpers.ApplyMarkerStyles(?color=Color)
231+
232+
233+
/// Computes the bi-dimensional histogram of two data samples and auto-determines the bin size.
234+
static member Histogram2d(x,y,?Name,?HistNorm,?HistFunc,?Colorscale,?Showscale,?zSmooth,?Colorbar,?zAuto,?zMin,?zMax,?nBinsx,?nBinsy,?Xbins,?Ybins) =
234235
let trace =
235236
Trace()
236-
|> Helpers.ApplyTraceStyles("histogram2d",x=x,y=y //?labels=labels,?name=Name,marker=marker,hole=hole
237-
238-
// hoverinfo: 'label+percent+name',
239-
// textinfo: 'none'
240-
// text
241-
// textposition
242-
)
237+
|> Helpers.ApplyTraceStyles("histogram2d",x=x,y=y,?name=Name,?histnorm=HistNorm,?histfunc=HistFunc,
238+
?colorScale=Colorscale,?showscale=Showscale,?zsmooth=zSmooth,?colorbar=Colorbar,
239+
?zauto=zAuto,?zmin=zMin,?zmax=zMax,
240+
?nbinsx=nBinsx,?nbinsy=nBinsy,?xbins=Xbins,?ybins=Ybins
241+
)
242+
243243
GenericChart.Chart (trace,None)
244244

245+
/// Computes the bi-dimensional histogram of two data samples and auto-determines the bin size.
246+
static member Histogram2d(xy,?Name,?HistNorm,?HistFunc,?Colorscale,?Showscale,?zSmooth,?Colorbar,?zAuto,?zMin,?zMax,?nBinsx,?nBinsy,?Xbins,?Ybins) =
247+
let x,y = Seq.unzip xy
248+
Chart.Histogram2d(x,y,?Name=Name,?HistNorm=HistNorm,?HistFunc=HistFunc,?Colorscale=Colorscale,
249+
?Showscale=Showscale,?Colorbar=Colorbar,?zSmooth=zSmooth,?zAuto=zAuto,?zMin=zMin,?zMax=zMax,
250+
?nBinsx=nBinsx,?nBinsy=nBinsy,?Xbins=Xbins,?Ybins=Ybins
251+
)
252+
253+
245254

246255

247256
// static member Point3D(x, y, z, ?Name,?ShowMarkers,?Showlegend,?Color,?Opacity,?Labels) =
@@ -266,7 +275,5 @@ type Chart =
266275

267276

268277

269-
//pie
270-
///
271278

272279

src/FSharp.Plotly/ChartHelpers.fs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ type private Helpers() =
4343
?opacity: float,
4444
?colorScale: StyleOption.ColorScale,
4545
?showscale,
46-
?zsmooth,
4746
?colorbar : Colorbar,
47+
?zsmooth,
48+
?zauto:bool,
49+
?zmin:float,
50+
?zmax:float,
51+
4852

4953
?uid: string, ?stream: Stream, ?connectgaps: bool, ?r: _, ?t: _,
5054
?error_y: Error,
@@ -55,8 +59,14 @@ type private Helpers() =
5559
//
5660
?hole,
5761
//Histo2d
58-
?histnorm
59-
62+
?histnorm,
63+
?histfunc,
64+
?autobinx:bool,
65+
?nbinsx:int,
66+
?xbins:Xbins,
67+
?autobiny:bool,
68+
?nbinsy:int,
69+
?ybins:Ybins
6070
) =
6171
(fun (trace:Trace) ->
6272
trace.set_type plotType
@@ -85,9 +95,12 @@ type private Helpers() =
8595
fill |> Option.iter (StyleOption.Fill.toString >> trace.set_fill)
8696
fillcolor |> Option.iter trace.set_fillcolor
8797
colorScale |> Option.iter (StyleOption.ColorScale.convert >> trace.set_colorscale)
88-
showscale |> Option.iter trace.set_showscale
89-
zsmooth |> Option.iter trace.set_zsmooth
90-
colorbar |> Option.iter trace.set_colorbar
98+
showscale |> Option.iter trace.set_showscale
99+
colorbar |> Option.iter trace.set_colorbar
100+
zsmooth |> Option.iter (StyleOption.SmoothAlg.convert >> trace.set_zsmooth)
101+
zauto |> Option.iter trace.set_zauto
102+
zmin |> Option.iter trace.set_zmin
103+
zmax |> Option.iter trace.set_zmax
91104

92105
marker |> Option.iter trace.set_marker
93106

@@ -107,6 +120,14 @@ type private Helpers() =
107120
hole |> Option.iter trace.set_hole
108121
// Histogram2d
109122
histnorm |> Option.iter (StyleOption.HistNorm.convert >> trace.set_histnorm)
123+
histfunc |> Option.iter (StyleOption.HistFunc.toString >> trace.set_histnorm)
124+
autobinx |> Option.iter trace.set_autobinx
125+
nbinsx |> Option.iter trace.set_nbinsx
126+
xbins |> Option.iter trace.set_xbins
127+
autobiny |> Option.iter trace.set_autobiny
128+
nbinsy |> Option.iter trace.set_nbinsy
129+
ybins |> Option.iter trace.set_ybins
130+
110131

111132
trace
112133
)

src/FSharp.Plotly/StyleOption.fs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,5 +426,30 @@ module StyleOption =
426426
static member convert = HistNorm.toString >> box
427427

428428

429+
/// Sets the binning function used for this histogram trace. The default value is 'count' where the histogram values are computed
430+
/// by counting the number of values lying inside each bin. With 'histfunc' set to 'sum', 'avg', 'min' or 'max', the histogram values
431+
/// are computed using the sum, the average, the minimum or the 'maximum' of the values lying inside each bin respectively.
432+
type HistFunc =
433+
| Count | Sum | Avg | Min | Max
434+
435+
static member toString = function
436+
| Count -> "count"
437+
| Sum -> "sum"
438+
| Avg -> "avg"
439+
| Min -> "min"
440+
| Max -> "max"
441+
442+
static member convert = HistNorm.toString >> box
443+
444+
445+
/// Choose between algorithms ('best' or 'fast') to smooth data linked to 'z'. The default value is false corresponding to no smoothing.
446+
type SmoothAlg =
447+
| False | Best | Fast
448+
449+
static member convert = function
450+
| False -> box false
451+
| Best -> box "best"
452+
| Fast -> box "fast"
453+
429454

430455

0 commit comments

Comments
 (0)