WebGL vs SVG in F#
How to make WebGL Charts in F# with Plotly.
In [1]:
#r "nuget: Plotly.NET, 2.0.0-preview.8"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.8"
#r "nuget: FSharp.Stats"
The following trace types use WebGL for part or all of the rendering through UseWebGL property
- Chart.Scatter
- Chart.Point
- Chart.Line
- Chart.Spline
- Chart.Bubble
WebGL with 100,000 points using Scatter Plot¶
In [2]:
open Plotly.NET
open Plotly.NET.TraceObjects
open FSharp.Stats.Distributions
open System
let N = 100000
let rs =
let normal = Continuous.uniform -1. 1.
Array.init N (fun _ -> normal.Sample())
let thetas =
let normal = Continuous.uniform 0.0 (2.*Math.PI)
Array.init N (fun _ -> normal.Sample())
let xs = thetas |> Seq.zip rs |> Seq.map(fun (r,t)-> r*Math.Cos(t) )
let ys = thetas |> Seq.zip rs |> Seq.map(fun (r,t)-> r*Math.Sin(t))
let marker = Marker.init(Colorscale=StyleParam.Colorscale.Bluered, Line=Line.init(Width=1.,Color=Color.fromString "DarkSlateGrey"))
Chart.Scatter(xs, ys, StyleParam.Mode.Markers, UseWebGL= true)
|> Chart.withMarker(marker)
Out[2]: