11module Chart2DTestCharts
22
3+ open System
34open Plotly.NET
5+ open Plotly.NET .TraceObjects
6+
7+ open TestUtils.DataGeneration
48
59module Point =
610
@@ -78,7 +82,6 @@ module Spline =
7882 let y = [ 2. ; 1.5 ; 5. ; 1.5 ; 3. ; 2.5 ; 2.5 ; 1.5 ; 3.5 ; 1. ]
7983 Chart.Spline( x = x, y = y, Name= " spline" , UseDefaults = false )
8084
81-
8285module Bubble =
8386
8487 let ``Simple bubble chart`` =
@@ -132,7 +135,6 @@ module StackedArea =
132135 ]
133136 |> Chart.combine
134137
135-
136138module Funnel = ()
137139
138140module StackedFunnel = ()
@@ -175,15 +177,100 @@ module Column =
175177
176178module StackedColumn = ()
177179
178- module Histogram = ()
180+ module Histogram =
181+
182+ let ``Simple histogram`` =
183+ let rnd = System.Random( 5 )
184+ let x = [ for i= 0 to 500 do yield rnd.NextDouble() ]
185+ Chart.Histogram( X = x, UseDefaults = false )
186+ |> Chart.withSize( 500 , 500 )
187+
179188
180- module Histogram2D = ()
189+ module Histogram2D =
190+
191+ let ``Histogram2D of 2D normal distribution`` =
192+ let rnd = System.Random( 5 )
193+ let n = 2000
194+ let a = - 1.
195+ let b = 1.2
196+ let step i = a + (( b - a) / float ( n - 1 )) * float i
197+
198+ //---------------------- generate data distributed in x and y direction ----------------------
199+ let x = Array.init n ( fun i -> (( step i)** 3. ) + ( 0.3 * ( normal ( rnd) 0. 2. ) ))
200+ let y = Array.init n ( fun i -> (( step i)** 6. ) + ( 0.3 * ( normal ( rnd) 0. 2. ) ))
201+ Chart.Histogram2D ( x = x, y = y, UseDefaults = false )
202+
203+ module BoxPlot =
204+
205+ let ``Simple boxplot with boxpoints`` =
206+ let y = [ 2. ; 1.5 ; 5. ; 1.5 ; 3. ; 2.5 ; 2.5 ; 1.5 ; 3.5 ; 1. ]
207+ let x = [ " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin1" ; " bin2" ; " bin1" ]
208+ Chart.BoxPlot( X = x, Y = y, Jitter= 0.1 , BoxPoints= StyleParam.BoxPoints.All, UseDefaults = false )
209+
210+ let ``Simple horizontal boxplot with boxpoints`` =
211+ let y = [ 2. ; 1.5 ; 5. ; 1.5 ; 3. ; 2.5 ; 2.5 ; 1.5 ; 3.5 ; 1. ]
212+ let x = [ " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin1" ; " bin2" ; " bin1" ]
213+ Chart.BoxPlot( X = y, Y = x, Jitter= 0.1 , BoxPoints= StyleParam.BoxPoints.All, Orientation= StyleParam.Orientation.Horizontal, UseDefaults = false )
214+
215+ let ``Combined chart with 2 horizontal boxplots`` =
216+ let y = [ 2. ; 1.5 ; 5. ; 1.5 ; 3. ; 2.5 ; 2.5 ; 1.5 ; 3.5 ; 1. ]
217+ 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. ]
218+ [
219+ Chart.BoxPlot( data = y , orientation = StyleParam.Orientation.Horizontal, Name= " bin1" , Jitter= 0.1 , BoxPoints= StyleParam.BoxPoints.All, UseDefaults = false );
220+ Chart.BoxPlot( data = y', orientation = StyleParam.Orientation.Horizontal, Name= " bin2" , Jitter= 0.1 , BoxPoints= StyleParam.BoxPoints.All, UseDefaults = false );
221+ ]
222+ |> Chart.combine
223+
224+ module Violin =
225+
226+ let ``Simple violin plot with jitterpoints`` =
227+ let y = [ 2. ; 1.5 ; 5. ; 1.5 ; 3. ; 2.5 ; 2.5 ; 1.5 ; 3.5 ; 1. ]
228+ let x = [ " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin1" ; " bin2" ; " bin1" ]
229+ Chart.Violin (
230+ X = x, Y = y,
231+ Points= StyleParam.JitterPoints.All,
232+ UseDefaults = false
233+ )
234+
235+ let ``Simple horizontal violin plot with jitterpoints`` =
236+ let y = [ 2. ; 1.5 ; 5. ; 1.5 ; 3. ; 2.5 ; 2.5 ; 1.5 ; 3.5 ; 1. ]
237+ let x = [ " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin2" ; " bin1" ; " bin1" ; " bin2" ; " bin1" ]
238+ Chart.Violin(
239+ X = y, Y = x,
240+ Jitter= 0.1 ,
241+ Points= StyleParam.JitterPoints.All,
242+ Orientation= StyleParam.Orientation.Horizontal,
243+ MeanLine= MeanLine.init( Visible= true ),
244+ UseDefaults = false
245+ )
246+
247+ let ``Combined chart with 2 horizontal violin plots`` =
248+ let y = [ 2. ; 1.5 ; 5. ; 1.5 ; 3. ; 2.5 ; 2.5 ; 1.5 ; 3.5 ; 1. ]
249+ 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. ]
250+ [
251+ Chart.Violin ( data = y , orientation = StyleParam.Orientation.Horizontal, Name= " bin1" , Jitter= 0.1 , Points= StyleParam.BoxPoints.All, UseDefaults = false )
252+ Chart.Violin ( data = y', orientation = StyleParam.Orientation.Horizontal, Name= " bin2" , Jitter= 0.1 , Points= StyleParam.BoxPoints.All, UseDefaults = false )
253+ ]
254+ |> Chart.combine
181255
182- module BoxPlot = ()
256+ module Histogram2DContour =
183257
184- module Violin = ()
258+ let ``Histogram2DContour of 2D normal distribution`` =
185259
186- module Histogram2DContour = ()
260+ let rnd = System.Random( 5 )
261+ let n = 2000
262+ let a = - 1.
263+ let b = 1.2
264+ let step i = a + (( b - a) / float ( n - 1 )) * float i
265+
266+ //---------------------- generate data distributed in x and y direction ----------------------
267+ let x = Array.init n ( fun i -> (( step i)** 3. ) + ( 0.3 * ( normal ( rnd) 0. 2. ) ))
268+ let y = Array.init n ( fun i -> (( step i)** 6. ) + ( 0.3 * ( normal ( rnd) 0. 2. ) ))
269+ [
270+ Chart.Histogram2DContour ( x = x, y = y, ContourLine= Line.init( Width= 0. ), UseDefaults = false )
271+ Chart.Point( x = x, y = y, Opacity= 0.3 , UseDefaults = false )
272+ ]
273+ |> Chart.combine
187274
188275module Heatmap =
189276
@@ -290,12 +377,65 @@ module Image =
290377 )
291378 |> Chart.withTitle " This is Plotly.NET:"
292379
293- module Contour = ()
380+ module Contour =
381+
382+ let ``Contour plot with peak and sink`` =
383+
384+ // Create example data
385+ let size = 100
386+ let x = linspace(- 2. * Math.PI, 2. * Math.PI, size)
387+ let y = linspace(- 2. * Math.PI, 2. * Math.PI, size)
388+
389+ let f x y = - ( 5. * x / ( x** 2. + y** 2. + 1. ) )
390+
391+ let z =
392+ Array.init size ( fun i ->
393+ Array.init size ( fun j ->
394+ f x.[ j] y.[ i]
395+ )
396+ )
397+
398+ Chart.Contour( zData = z, UseDefaults = false )
399+ |> Chart.withSize( 600. , 600. )
294400
295401module OHLC = ()
296402
297403module Candlestick = ()
298404
299- module Splom = ()
405+ module Splom =
406+
407+ let ``Simple scatterplot matrix`` =
408+ let data =
409+ [
410+ " A" ,[| 1. ; 4. ; 3.4 ; 0.7 ;|]
411+ " B" ,[| 3. ; 1.5 ; 1.7 ; 2.3 ;|]
412+ " C" ,[| 2. ; 4. ; 3.1 ; 5. |]
413+ " D" ,[| 4. ; 2. ; 2. ; 4. ;|]
414+ ]
415+ Chart.Splom( keyValues = data, MarkerColor= Color.fromString " blue" , UseDefaults = false )
416+
417+
418+ module PointDensity =
300419
301- module PointDensity = ()
420+
421+ let ``Simple PointDensity chart`` =
422+ let rnd = new System.Random( 5 )
423+ let x = [ for i in 0 .. 100 -> rnd.NextDouble()]
424+ let y = [ for i in 0 .. 100 -> rnd.NextDouble()]
425+ Chart.PointDensity( x = x, y = y, UseDefaults = false )
426+
427+ let ``Styled PointDensity chart`` =
428+ let rnd = new System.Random( 5 )
429+ let x = [ for i in 0 .. 100 -> rnd.NextDouble()]
430+ let y = [ for i in 0 .. 100 -> rnd.NextDouble()]
431+ Chart.PointDensity(
432+ x = x,
433+ y = y,
434+ PointMarkerColor = Color.fromKeyword Purple,
435+ PointMarkerSymbol = StyleParam.MarkerSymbol.X,
436+ PointMarkerSize = 4 ,
437+ ColorScale = StyleParam.Colorscale.Viridis,
438+ ColorBar = ColorBar.init( Title = Title.init( " Density" )),
439+ ShowContourLabels = true ,
440+ UseDefaults = false
441+ )
0 commit comments