Skip to content

Commit 515f8ce

Browse files
committed
Fixed Scatter3d lines and added 3d surface plot
1 parent 3bf7aeb commit 515f8ce

File tree

10 files changed

+553
-206
lines changed

10 files changed

+553
-206
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### 1.0.2 - Sep 12 2016
2+
* Add Scatter3d line plots
3+
* Add 3d Surface plots
4+
15
### 1.0.1 - July 5 2016
26
* More awesome stuff coming...
37
* More 3d-Charts

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,35 @@
33
#r "../../bin/FSharp.Plotly.dll"
44

55
(**
6-
# FSharp.Plotly: Pie and Doughnut Charts
6+
# FSharp.Plotly: Scatter3d Charts with lines
77
8-
*Summary:* This example shows how to create pie and doughnut charts in F#.
8+
*Summary:* This example shows how to create three-dimensional scatter charts 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 Scatter3d chart report shows a three-dimensional spinnable view of your data as line with markers
1311
*)
1412

1513
open FSharp.Plotly
14+
open System
15+
16+
let c = [0. .. 0.5 .. 15.]
17+
18+
let x,y,z =
19+
c
20+
|> List.map (fun i ->
21+
let i' = float i
22+
let r = 10. * Math.Cos (i' / 10.)
23+
(r*Math.Cos i',r*Math.Sin i',i')
24+
)
25+
|> List.unzip3
26+
1627

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 ***)
28+
(*** define-output:scatter3d_line_1 ***)
29+
Chart.Scatter3d(x,y,z,StyleOption.Mode.Lines_Markers)
30+
|> Chart.withX_AxisStyle("x-axis")
31+
|> Chart.withY_AxisStyle("y-axis")
32+
|> Chart.withZ_AxisStyle("z-axis")
33+
|> Chart.withSize(800.,800.)
34+
35+
(*** include-it:scatter3d_line_1 ***)
36+
2337

24-
(*** define-output:doughnut1 ***)
25-
Chart.Doughnut(values,labels,Hole=0.3)
26-
(*** include-it:doughnut1 ***)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ Chart.Scatter3d(x,y,z,StyleOption.Mode.Markers)
3232

3333

3434

35+
36+

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

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,41 @@ When creating pie or doughnut charts, it is usually desirable to provide both la
1212
values.
1313
*)
1414

15+
open System
1516
open FSharp.Plotly
17+
18+
19+
// Generate linearly spaced vector
20+
let linspace (min,max,n) =
21+
if n <= 2 then failwithf "n needs to be larger then 2"
22+
let bw = float (max - min) / (float n - 1.)
23+
Array.init n (fun i -> min + (bw * float i))
24+
//[|min ..bw ..max|]
1625

17-
let values = [19; 26; 55;]
18-
let labels = ["Residential"; "Non-Residential"; "Utility"]
26+
27+
// Create example data
28+
let size = 100
29+
let x = linspace(-2. * Math.PI, 2. * Math.PI, size)
30+
let y = linspace(-2. * Math.PI, 2. * Math.PI, size)
31+
32+
let f x y = - (5. * x / (x**2. + y**2. + 1.) )
33+
34+
let z =
35+
Array.init size (fun i ->
36+
Array.init size (fun j -> f x.[j] y.[i] )
37+
)
38+
39+
1940

20-
(*** define-output:pie1 ***)
21-
Chart.Pie(values,labels)
22-
(*** include-it:pie1 ***)
41+
(*** define-output:contour1 ***)
42+
z
43+
|> Chart.Surface
44+
|> Chart.withSize(600.,600.)
45+
(*** include-it:contour1 ***)
46+
47+
48+
49+
50+
51+
2352

24-
(*** define-output:doughnut1 ***)
25-
Chart.Doughnut(values,labels,Hole=0.3)
26-
(*** include-it:doughnut1 ***)

docs/content/box-plots.fsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,29 @@ let y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
1919
let x = ["bin1";"bin2";"bin1";"bin2";"bin1";"bin2";"bin1";"bin1";"bin2";"bin1"]
2020

2121
(*** define-output:box1 ***)
22-
Chart.BoxPlot(x,y,Jitter=0.3,Boxpoints=StyleOption.Boxpoints.Outliers)
22+
Chart.BoxPlot(x,y,Jitter=0.1,Boxpoints=StyleOption.Boxpoints.All)
2323
(*** include-it:box1 ***)
24+
25+
(**
26+
By swapping x and y plus using `StyleOption.Orientation.Horizontal` we can flip the chart horizontaly.
27+
*)
28+
(*** define-output:box2 ***)
29+
Chart.BoxPlot(y,x,Jitter=0.1,Boxpoints=StyleOption.Boxpoints.All,Orientation=StyleOption.Orientation.Horizontal)
30+
(*** include-it:box2 ***)
31+
32+
33+
34+
(**
35+
You can also produce a boxplot using the `Chart.Combine` syntax.
36+
*)
37+
38+
let y' = [2.; 1.5; 5.; 1.5; 2.; 2.5; 2.1; 2.5; 1.5; 1.;2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]
39+
40+
(*** define-output:box3 ***)
41+
[
42+
Chart.BoxPlot("y" ,y,Name="bin1",Jitter=0.1,Boxpoints=StyleOption.Boxpoints.All);
43+
Chart.BoxPlot("y'",y',Name="bin2",Jitter=0.1,Boxpoints=StyleOption.Boxpoints.All);
44+
]
45+
|> Chart.Combine
46+
(*** include-it:box3 ***)
47+

docs/tools/formatters.fsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ let createFsiEvaluator root output =
4343

4444
| :? GenericChart.GenericChart as ch ->
4545
// Just return the inline HTML for a Plotly chart
46-
let html = GenericChart.toChartHtmlWithSize 500 500 ch
46+
let html = GenericChart.toChartHtmlWithSize 700 500 ch
4747
Some [InlineBlock <| html]
4848

4949
| _ -> None

docs/tools/templates/template.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
<li><a href="@Root/range-plots.html">Range Plots</a></li>
5858
<li class="nav-header">Plotly 3d-Charts</li>
5959
<li><a href="@Root/3d-scatter-plots.html">3D Scatter Plots</a></li>
60-
@*<li><a href="@Root/3d-line-plots.html">3D Line Plots</a></li>
61-
<li><a href="@Root/3d-surface-plots.html">3D Surface Plots</a></li>*@
60+
<li><a href="@Root/3d-line-plots.html">3D Line Plots</a></li>
61+
<li><a href="@Root/3d-surface-plots.html">3D Surface Plots</a></li>
6262
<li class="nav-header">Plotly WPF</li>
6363
<li><a href="@Root/plotly-wpf.html">Using Plotly PopUp window</a></li>
6464

src/FSharp.Plotly/Chart.fs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,3 +376,14 @@ type Chart =
376376
static member Scatter3d(xyz, mode, ?Name,?Showlegend,?MarkerSymbol,?Color,?Opacity,?Labels,?TextPosition,?TextFont,?Dash,?Width) =
377377
let x,y,z = Seq.unzip3 xyz
378378
Chart.Scatter3d(x, y, z, mode, ?Name=Name,?Showlegend=Showlegend,?MarkerSymbol=MarkerSymbol,?Color=Color,?Opacity=Opacity,?Labels=Labels,?TextPosition=TextPosition,?TextFont=TextFont,?Dash=Dash,?Width=Width)
379+
380+
/// Uses points, line or both depending on the mode to represent 3d-data points
381+
static member Surface(data:seq<#seq<#IConvertible>>,?X,?Y, ?Name,?Showlegend,?Opacity,?Colorscale,?Showscale,?zSmooth,?Colorbar) =
382+
let trace =
383+
Trace3dObjects.Surface()
384+
|> Options.IMapZ(Z=data,?X=X, ?Y=Y)
385+
|> Options.IColormap(?Colorscale=Colorscale,?Showscale=Showscale,?zSmooth=zSmooth,?Colorbar=Colorbar)
386+
|> Options.ITraceInfo(?Name=Name,?Showlegend=Showlegend,?Opacity=Opacity)
387+
//|> Options.ITextLabel(?Text=Labels,?Textposition=TextPosition,?Textfont=TextFont)
388+
GenericChart.Chart (trace,None)
389+

src/FSharp.Plotly/StyleOption.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ module StyleOption =
182182

183183
type Orientation =
184184
| Horizontal
185-
| Vertival
185+
| Vertical
186186

187187
static member convert = function
188188
| Horizontal -> box "h"
189-
| Vertival -> box "v"
189+
| Vertical -> box "v"
190190

191191
/// The colorscale must be a collection containing a mapping of a normalized value (between 0.0 and 1.0) to it's color. At minimum, a mapping for the lowest (0.0) and highest (1.0) values are required.
192192
type ColorScale =

0 commit comments

Comments
 (0)