1+ module Chart3DTestCharts
2+
3+ open Plotly.NET
4+ open Plotly.NET .TraceObjects
5+ open System
6+
7+ open TestUtils.DataGeneration
8+
9+ module Scatter3D =
10+
11+ let ``Simple scatter3d chart with axis titles`` =
12+ let x = [ 19 ; 26 ; 55 ;]
13+ let y = [ 19 ; 26 ; 55 ;]
14+ let z = [ 19 ; 26 ; 55 ;]
15+
16+ Chart.Scatter3D( x = x, y = y, z = z, mode = StyleParam.Mode.Markers, UseDefaults = false )
17+ |> Chart.withXAxisStyle( " my x-axis" , Id= StyleParam.SubPlotId.Scene 1 )
18+ |> Chart.withYAxisStyle( " my y-axis" , Id= StyleParam.SubPlotId.Scene 1 )
19+ |> Chart.withZAxisStyle( " my z-axis" )
20+ |> Chart.withSize( 800 , 800 )
21+
22+ module Point3D =
23+
24+ let ``Simple Point3D chart with axis titles`` =
25+ let x = [ 19 ; 26 ; 55 ;]
26+ let y = [ 19 ; 26 ; 55 ;]
27+ let z = [ 19 ; 26 ; 55 ;]
28+
29+ Chart.Point3D( x = x, y = y, z = z, UseDefaults = false )
30+ |> Chart.withXAxisStyle( " my x-axis" , Id= StyleParam.SubPlotId.Scene 1 )
31+ |> Chart.withYAxisStyle( " my y-axis" , Id= StyleParam.SubPlotId.Scene 1 )
32+ |> Chart.withZAxisStyle( " my z-axis" )
33+ |> Chart.withSize( 800 , 800 )
34+
35+
36+
37+ module Line3D =
38+ let ``Upwards spiral line 3D chart with markers`` =
39+ let c = [ 0. .. 0.5 .. 15. ]
40+
41+ let x , y , z =
42+ c
43+ |> List.map ( fun i ->
44+ let i ' = float i
45+ let r = 10. * Math.Cos ( i' / 10. )
46+ ( r * Math.Cos i', r * Math.Sin i', i')
47+ |> fun ( x , y , z ) ->
48+ Math.Round( x, 3 ),
49+ Math.Round( y, 3 ),
50+ Math.Round( z, 3 )
51+ )
52+ |> List.unzip3
53+
54+ Chart.Line3D( x = x, y = y, z = z, ShowMarkers= true , UseDefaults = false )
55+ |> Chart.withXAxisStyle( " x-axis" , Id= StyleParam.SubPlotId.Scene 1 )
56+ |> Chart.withYAxisStyle( " y-axis" , Id= StyleParam.SubPlotId.Scene 1 )
57+ |> Chart.withZAxisStyle( " z-axis" )
58+ |> Chart.withSize( 800 , 800 )
59+
60+
61+ module Bubble3D =
62+
63+ let ``Simple Bubble3D chart with axis titles`` =
64+ Chart.Bubble3D(
65+ xyz = [ 1 , 3 , 2 ; 6 , 5 , 4 ; 7 , 9 , 8 ],
66+ sizes = [ 20 ; 40 ; 30 ],
67+ MultiText = [ " A" ; " B" ; " C" ],
68+ TextPosition = StyleParam.TextPosition.TopLeft,
69+ UseDefaults = false
70+ )
71+ |> Chart.withXAxisStyle( " x-axis" , Id= StyleParam.SubPlotId.Scene 1 )
72+ |> Chart.withYAxisStyle( " y-axis" , Id= StyleParam.SubPlotId.Scene 1 )
73+ |> Chart.withZAxisStyle( " z-axis" )
74+
75+ module Surface =
76+
77+ let ``Peak and sink surface plot`` =
78+
79+ //---------------------- Create example data ----------------------
80+ let size = 100
81+ let x = linspace(- 2. * Math.PI, 2. * Math.PI, size)
82+ let y = linspace(- 2. * Math.PI, 2. * Math.PI, size)
83+
84+ let f x y = - ( 5. * x / ( x** 2. + y** 2. + 1. ) )
85+
86+ let z =
87+ Array.init size ( fun i ->
88+ Array.init size ( fun j -> f x.[ j] y.[ i] )
89+ )
90+
91+ Chart.Surface( zData = z, UseDefaults = false )
92+
93+ let ``Surface plot with x / y indices mapping to z matrix with contours`` =
94+ let x ' = [ 0. ; 2.5 ]
95+ let y ' = [ 0. ; 2.5 ]
96+ let z ' = [
97+ [ 1. ; 1. ;]; // row wise (length x)
98+ [ 1. ; 2. ;];
99+ ] // column (length y)
100+
101+ Chart.Surface( zData = z', X = x', Y = y', Opacity= 0.5 , Contours= Contours.initXyz( Show= true ), UseDefaults = false )
102+
103+
104+ module Mesh3D =
105+
106+ let ``Mesh3D chart with random x / x / z data`` =
107+
108+ let rnd = System.Random( 5 )
109+ let x = Array.init 50 ( fun _ -> rnd.NextDouble())
110+ let y = Array.init 50 ( fun _ -> rnd.NextDouble())
111+ let z = Array.init 50 ( fun _ -> rnd.NextDouble())
112+
113+ Chart.Mesh3D(
114+ x = x,
115+ y = y,
116+ z = z,
117+ FlatShading = true ,
118+ Contour = Contour.init( Show = true ),
119+ UseDefaults = false
120+ )
121+
122+ module Cone =
123+
124+ let ``Simple cone chart`` =
125+ Chart.Cone(
126+ x = [ 1 ; 1 ; 1 ],
127+ y = [ 1 ; 2 ; 3 ],
128+ z = [ 1 ; 1 ; 1 ],
129+ u = [ 1 ; 2 ; 3 ],
130+ v = [ 1 ; 1 ; 2 ],
131+ w = [ 4 ; 4 ; 1 ],
132+ ColorScale = StyleParam.Colorscale.Viridis,
133+ UseDefaults = false
134+ )
135+
136+ module StreamTube =
137+
138+ let ``Simple StreamTube chart `` =
139+ Chart.StreamTube(
140+ x = [ 0 ; 0 ; 0 ],
141+ y = [ 0 ; 1 ; 2 ],
142+ z = [ 0 ; 0 ; 0 ],
143+ u = [ 0 ; 0 ; 0 ],
144+ v = [ 1 ; 1 ; 1 ],
145+ w = [ 0 ; 0 ; 0 ],
146+ ColorScale = StyleParam.Colorscale.Viridis,
147+ UseDefaults = false
148+ )
149+
150+ module Volume =
151+
152+ let ``Fancy mgrid based volume chart`` =
153+ let x , y , z = mgrid( 1. , 2. , 4 )
154+ Chart.Volume(
155+ x = ( x |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
156+ y = ( y |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
157+ z = ( z |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
158+ value = ( z |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
159+ ColorScale = StyleParam.Colorscale.Viridis,
160+ UseDefaults = false
161+ )
162+
163+ module IsoSurface =
164+
165+ let ``Fancy mgrid based isosurface chart`` =
166+ let x , y , z = mgrid( 1. , 2. , 4 )
167+ Chart.IsoSurface(
168+ x = ( x |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
169+ y = ( y |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
170+ z = ( z |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
171+ value = ( z |> Array.concat |> Array.concat |> Array.map ( fun x -> Math.Round( x, 3 ))),
172+ ColorScale = StyleParam.Colorscale.Viridis,
173+ UseDefaults = false
174+ )
0 commit comments