### XPlot

Plotly 2D Histograms

## 2D Histogram of a Bivariate Normal Distribution

open MathNet.Numerics.Distributions
open XPlot.Plotly

let normal = Normal(0., 1.0)

let x =
normal.Samples()
|> Seq.take 500

let y =
normal.Samples()
|> Seq.take 500
|> Seq.map (fun x -> x + 1.)

let x0 =
normal.Samples()
|> Seq.take 100
|> Seq.map (fun x -> x / 5. + 0.5)

let y0 =
normal.Samples()
|> Seq.take 100
|> Seq.map (fun x -> x / 5. + 0.5)

let uniform = ContinuousUniform(0., 1.0)

let x1 =
uniform.Samples()
|> Seq.take 50

let y1 =
uniform.Samples()
|> Seq.take 50
|> Seq.map (fun x -> x + 1.)

let x' = Seq.concat [x0; x1]
let y' = Seq.concat [y0; y1]

let chart1 =
Histogram2d(
x = x,
y = y
)
|> Chart.Plot
|> Chart.WithWidth 700
|> Chart.WithHeight 500


## 2D Histogram Binning and Styling Options

let chart2 =
Histogram2d(
x = x,
y = y,
histnorm = "probability",
autobinx = false,
xbins =
Xbins(
start = -3.,
end = 3.,
size = 0.1
),
autobiny = false,
ybins =
Ybins(
start = -2.5,
end = 4.,
size = 0.1
),
colorscale =
[
[box 0; box "rgb(12,51,131)"]
[0.25; "rgb(10,136,186)"]
[0.5; "rgb(242,211,56)"]
[0.75; "rgb(242,143,56)"]
[1; "rgb(217,30,30)"]
]
)
|> Chart.Plot
|> Chart.WithWidth 700
|> Chart.WithHeight 500


## 2D Histogram Overlaid with a Scatter Chart

let trace1 =
Scatter(
x = x0,
y = y0,
mode = "markers",
marker =
Marker(
symbol = "circle",
opacity = 0.7
)
)

let trace2 =
Scatter(
x = x1,
y = y1,
mode = "markers",
marker =
Marker(
symbol = "square",
opacity = 0.7
)
)

let trace3 =
Histogram2d(
x = x',
y = y'
)

let layout = Layout(showlegend = false)

let chart3 =
[trace1 :> Trace; trace2 :> _; trace3 :> _]
|> Chart.Plot
|> Chart.WithWidth 700
|> Chart.WithHeight 500
|> Chart.WithLayout layout

namespace MathNet
namespace MathNet.Numerics
namespace MathNet.Numerics.Distributions
namespace XPlot
namespace XPlot.Plotly
val normal : Normal
Multiple items
type Normal =
interface IContinuousDistribution
interface IUnivariateDistribution
interface IDistribution
new : unit -> unit + 3 overloads
member CumulativeDistribution : x: float -> float
member Density : x: float -> float
member DensityLn : x: float -> float
member InverseCumulativeDistribution : p: float -> float
member Sample : unit -> float + 2 overloads
member Samples : values: float [] -> unit + 5 overloads
...

--------------------
Normal() : Normal
Normal(randomSource: System.Random) : Normal
Normal(mean: float, stddev: float) : Normal
Normal(mean: float, stddev: float, randomSource: System.Random) : Normal
val x : seq<float>
Normal.Samples() : System.Collections.Generic.IEnumerable<float>
Normal.Samples(values: float []) : unit
module Seq

from Microsoft.FSharp.Collections
val take : count:int -> source:seq<'T> -> seq<'T>
val y : seq<float>
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>
val x : float
val x0 : seq<float>
val y0 : seq<float>
val uniform : ContinuousUniform
Multiple items
type ContinuousUniform =
interface IContinuousDistribution
interface IUnivariateDistribution
interface IDistribution
new : unit -> unit + 2 overloads
member CumulativeDistribution : x: float -> float
member Density : x: float -> float
member DensityLn : x: float -> float
member InverseCumulativeDistribution : p: float -> float
member Sample : unit -> float + 2 overloads
member Samples : values: float [] -> unit + 5 overloads
...

--------------------
ContinuousUniform() : ContinuousUniform
ContinuousUniform(lower: float, upper: float) : ContinuousUniform
ContinuousUniform(lower: float, upper: float, randomSource: System.Random) : ContinuousUniform
val x1 : seq<float>
ContinuousUniform.Samples() : System.Collections.Generic.IEnumerable<float>
ContinuousUniform.Samples(values: float []) : unit
val y1 : seq<float>
val x' : seq<float>
val concat : sources:seq<#seq<'T>> -> seq<'T>
val y' : seq<float>
val chart1 : PlotlyChart
Multiple items
type Histogram2d =
inherit Trace
new : unit -> Histogram2d
member ShouldSerializeautobinx : unit -> bool
member ShouldSerializeautobiny : unit -> bool
member ShouldSerializeautocolorscale : unit -> bool
member ShouldSerializecolorbar : unit -> bool
member ShouldSerializecolorscale : unit -> bool
member ShouldSerializeconnectgaps : unit -> bool
member ShouldSerializedx : unit -> bool
member ShouldSerializedy : unit -> bool
...

--------------------
new : unit -> Histogram2d
property Histogram2d.x: obj with get, set
property Histogram2d.y: obj with get, set
type Chart =
static member Area : data:seq<#value> -> PlotlyChart + 2 overloads
static member Bar : data:seq<#value> -> PlotlyChart + 2 overloads
static member Bubble : data:seq<#key * #value * #value> -> PlotlyChart
static member Candlestick : data:seq<#key * #value * #value * #value * #value> -> PlotlyChart
static member Column : data:seq<#value> -> PlotlyChart + 2 overloads
static member Line : data:seq<#value> -> PlotlyChart + 2 overloads
static member Pie : data:seq<#key * #value> -> PlotlyChart
static member Plot : data:Trace -> PlotlyChart + 3 overloads
static member Scatter : data:seq<#value> -> PlotlyChart + 2 overloads
static member Show : chart:PlotlyChart -> unit
...
static member Chart.Plot : data:seq<#Trace> -> PlotlyChart
static member Chart.Plot : data:Trace -> PlotlyChart
static member Chart.Plot : data:seq<#Trace> * layout:Layout -> PlotlyChart
static member Chart.Plot : data:Trace * layout:Layout -> PlotlyChart
static member Chart.WithWidth : width:int -> chart:PlotlyChart -> PlotlyChart
static member Chart.WithHeight : height:int -> chart:PlotlyChart -> PlotlyChart
member PlotlyChart.GetHtml : unit -> string
val chart2 : PlotlyChart
Multiple items
type Xbins =
new : unit -> Xbins
member ShouldSerializeend : unit -> bool
member ShouldSerializesize : unit -> bool
member ShouldSerializestart : unit -> bool
member end : float
member size : obj
member start : float

--------------------
new : unit -> Xbins
Multiple items
type Ybins =
new : unit -> Ybins
member ShouldSerializeend : unit -> bool
member ShouldSerializesize : unit -> bool
member ShouldSerializestart : unit -> bool
member end : float
member size : obj
member start : float

--------------------
new : unit -> Ybins
val box : value:'T -> obj
val trace1 : Scatter
Multiple items
type Scatter =
inherit Trace
new : unit -> Scatter
member ShouldSerializeconnectgaps : unit -> bool
member ShouldSerializedx : unit -> bool
member ShouldSerializedy : unit -> bool
member ShouldSerializeerror_x : unit -> bool
member ShouldSerializeerror_y : unit -> bool
member ShouldSerializefill : unit -> bool
member ShouldSerializefillcolor : unit -> bool
member ShouldSerializehoverinfo : unit -> bool
...

--------------------
new : unit -> Scatter
property Scatter.x: obj with get, set
property Scatter.y: obj with get, set
Multiple items
type Marker =
new : unit -> Marker
member ShouldSerializeautocolorscale : unit -> bool
member ShouldSerializecauto : unit -> bool
member ShouldSerializecmax : unit -> bool
member ShouldSerializecmin : unit -> bool
member ShouldSerializecolor : unit -> bool
member ShouldSerializecolorbar : unit -> bool
member ShouldSerializecolors : unit -> bool
member ShouldSerializecolorscale : unit -> bool
member ShouldSerializecolorsrc : unit -> bool
...

--------------------
new : unit -> Marker
val trace2 : Scatter
val trace3 : Histogram2d
val layout : Layout
Multiple items
module Layout

from XPlot.Plotly

--------------------
type Layout =
new : unit -> Layout
member ShouldSerializeangularaxis : unit -> bool
member ShouldSerializeannotations : unit -> bool
member ShouldSerializeautosize : unit -> bool
member ShouldSerializebargap : unit -> bool
member ShouldSerializebargroupgap : unit -> bool
member ShouldSerializebarmode : unit -> bool
member ShouldSerializeboxmode : unit -> bool
member ShouldSerializedirection : unit -> bool
member ShouldSerializedragmode : unit -> bool
...

--------------------
new : unit -> Layout
val chart3 : PlotlyChart
Multiple items
type Trace =
new : unit -> Trace
member ShouldSerializename : unit -> bool
member name : string

--------------------
new : unit -> Trace
static member Chart.WithLayout : layout:Layout -> chart:PlotlyChart -> PlotlyChart