-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy path3d-isosurface-plots.fsx
More file actions
102 lines (79 loc) · 2.59 KB
/
Copy path3d-isosurface-plots.fsx
File metadata and controls
102 lines (79 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
(**
---
title: 3D IsoSurface plots
category: 3D Charts
categoryindex: 4
index: 7
---
*)
(*** hide ***)
(*** condition: prepare ***)
#r "nuget: Newtonsoft.JSON, 13.0.1"
#r "nuget: DynamicObj, 2.0.0"
#r "nuget: Giraffe.ViewEngine, 1.4.0"
#r "../../src/Plotly.NET/bin/Release/netstandard2.0/Plotly.NET.dll"
Plotly.NET.Defaults.DefaultDisplayOptions <-
Plotly.NET.DisplayOptions.init (PlotlyJSReference = Plotly.NET.PlotlyJSReference.NoReference)
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, {{fsdocs-package-version}}"
#r "nuget: Plotly.NET.Interactive, {{fsdocs-package-version}}"
#endif // IPYNB
(**
# 3D IsoSurface plots
[](https://mybinder.org/v2/gh/plotly/plotly.net/gh-pages?urlpath=/tree/home/jovyan/{{fsdocs-source-basename}}.ipynb) 
[]({{root}}{{fsdocs-source-basename}}.ipynb)
*Summary:* This example shows how to create 3D-IsoSurface charts in F#.
Let's first create some data for the purpose of creating example charts:
*)
open System
open Plotly.NET
let linspace (min, max, n) =
if n <= 2 then
failwithf "n needs to be larger then 2"
let bw = float (max - min) / (float n - 1.)
Array.init n (fun i -> min + (bw * float i))
let mgrid (min, max, n) =
let data = linspace (min, max, n)
let z =
[| for i in 1..n do
[| for i in 1..n do
yield data |] |]
let x =
[| for i in 1..n do
[| for j in 1..n do
yield
[| for k in 1..n do
yield data.[i - 1] |] |] |]
let y =
[| for i in 1..n do
[| for j in 1..n do
yield
[| for k in 1..n do
yield data.[j - 1] |] |] |]
x, y, z
let xIso, yIso, zIso =
mgrid (-5., 5., 40)
|> fun (x, y, z) ->
(x |> Array.concat |> Array.concat), (y |> Array.concat |> Array.concat), (z |> Array.concat |> Array.concat)
let valueIso =
Array.map3 (fun x y z -> x * x * 0.5 + y * y + z * z * 2.) xIso yIso zIso
open Plotly.NET.TraceObjects
let isoSurface =
Chart.IsoSurface(
x = xIso,
y = yIso,
z = zIso,
value = valueIso,
IsoMin = 10.,
IsoMax = 40.,
Caps = Caps.init (X = (CapFill.init (Show = false)), Y = (CapFill.init (Show = false))),
Surface = Surface.init (Count = 5)
)
(*** condition: ipynb ***)
#if IPYNB
isoSurface
#endif // IPYNB
(***hide***)
isoSurface |> GenericChart.toChartHTML
(*** include-it-raw ***)