3D Mesh plots

Summary: This example shows how to create 3D-Mesh charts in F#.

let's first create some data for the purpose of creating example charts:

open System
open Plotly.NET

//---------------------- Generate linearly spaced vector ----------------------
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))
//[|min ..bw ..max|]

//---------------------- Create example data ----------------------
let size = 100
let x = linspace(-2. * Math.PI, 2. * Math.PI, size)
let y = linspace(-2. * Math.PI, 2. * Math.PI, size)

let f x y = - (5. * x / (x**2. + y**2. + 1.) )

let z =
Array.init size (fun i ->
Array.init size (fun j ->
f x.[j] y.[i]
)
)

let rnd = System.Random()
let a = Array.init 50 (fun _ -> rnd.NextDouble())
let b = Array.init 50 (fun _ -> rnd.NextDouble())
let c = Array.init 50 (fun _ -> rnd.NextDouble())

let mesh3d =
Trace3d.initMesh3d
(fun mesh3d ->
mesh3d?x <- a
mesh3d?y <- b
mesh3d?z <- c
mesh3d?flatshading <- true
mesh3d?contour <- Contours.initXyz(Show=true)
mesh3d
)
|> GenericChart.ofTraceObject


namespace System
namespace Plotly
namespace Plotly.NET
val linspace : min:float * max:float * n:int -> float []
val min : float
val max : float
val n : int
val failwithf : format:Printf.StringFormat<'T,'Result> -> 'T
val bw : float
Multiple items
val float : value:'T -> float (requires member op_Explicit)

--------------------
[<Struct>]
type float = Double

--------------------
type float<'Measure> =
float
type Array =
interface ICollection
interface IEnumerable
interface IList
interface IStructuralComparable
interface IStructuralEquatable
interface ICloneable
new : unit -> unit
member Clone : unit -> obj
member CopyTo : array: Array * index: int -> unit + 1 overload
member GetEnumerator : unit -> IEnumerator
...
val init : count:int -> initializer:(int -> 'T) -> 'T []
val i : int
val size : int
val x : float []
type Math =
static member Abs : value: decimal -> decimal + 6 overloads
static member Acos : d: float -> float
static member Acosh : d: float -> float
static member Asin : d: float -> float
static member Asinh : d: float -> float
static member Atan : d: float -> float
static member Atan2 : y: float * x: float -> float
static member Atanh : d: float -> float
static member BigMul : a: int * b: int -> int64 + 2 overloads
static member BitDecrement : x: float -> float
...
field Math.PI: float = 3.14159265359
val y : float []
val f : x:float -> y:float -> float
val x : float
val y : float
val z : float [] []
val j : int
val rnd : Random
Multiple items
type Random =
new : unit -> unit + 1 overload
member Next : unit -> int + 2 overloads
member NextBytes : buffer: byte [] -> unit + 1 overload
member NextDouble : unit -> float
member Sample : unit -> float

--------------------
Random() : Random
Random(Seed: int) : Random
val a : float []
Random.NextDouble() : float
val b : float []
val c : float []
val mesh3d : GenericChart.GenericChart
Multiple items
module Trace3d

from Plotly.NET

--------------------
type Trace3d =
inherit Trace
new : traceTypeName:string -> Trace3d

--------------------
new : traceTypeName:string -> Trace3d
val initMesh3d : applyStyle:(Trace3d -> Trace3d) -> Trace3d
val mesh3d : Trace3d
Multiple items
type Contours =
inherit DynamicObj
new : unit -> Contours
static member init : ?X:Contour * ?Y:Contour * ?Z:Contour -> Contours
static member initXyz : ?Show:bool * ?Color:string * ?UseColorMap:bool * ?Width:float * ?Highlight:bool * ?Highlightcolor:string * ?Highlightwidth:float -> Contours
static member style : ?X:Contour * ?Y:Contour * ?Z:Contour -> (Contours -> Contours)
static member styleXyz : ?Show:bool * ?Color:string * ?UseColorMap:bool * ?Width:float * ?Highlight:bool * ?Highlightcolor:string * ?Highlightwidth:float -> (Contours -> Contours)

--------------------
new : unit -> Contours
static member Contours.initXyz : ?Show:bool * ?Color:string * ?UseColorMap:bool * ?Width:float * ?Highlight:bool * ?Highlightcolor:string * ?Highlightwidth:float -> Contours
module GenericChart

from Plotly.NET
val ofTraceObject : trace:Trace -> GenericChart.GenericChart
val toChartHTML : gChart:GenericChart.GenericChart -> string