// can't yet format YamlFrontmatter (["title: Contour plots"; "category: Distribution Charts"; "categoryindex: 5"; "index: 4"], Some { StartLine = 2 StartColumn = 0 EndLine = 6 EndColumn = 8 }) to pynb markdown

In [ ]:
#r "nuget: Plotly.NET, 2.0.0-preview.16"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.16"


# Contour plots¶

Summary: This example shows how to create contour plot in F#.

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

In [3]:
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.)
[|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]
)
)


A contour plot is a graphical technique for representing a 3-dimensional surface by plotting constant z slices, called contours, on a 2-dimensional format. That is, given a value for z, lines are drawn for connecting the (x,y) coordinates where that z value occurs.

The contour plot is an alternative to a 3-D surface plot.

In [4]:
let contour1 =
z
|> Chart.Contour
|> Chart.withSize(600.,600.)

In [ ]:
contour1

Out[ ]:

## Smooth Contour Coloring¶

to apply heatmap gradient coloring between each contour level, set the ContourColoring to heatmap:

In [6]:
let contour2 =
Chart.Contour(
z,
ContoursColoring = StyleParam.ContourColoring.Heatmap
)

In [ ]:
contour2

Out[ ]:

## Contour Line Labels¶

Use ContourLabelFont to set a contour label font, and display the labels with ShowContourLabels:

In [8]:
let contour3 =
Chart.Contour(
z,
ContoursColoring = StyleParam.ContourColoring.Heatmap,
ShowContourLabels = true,
ContourLabelFont = Font.init(Size = 12., Color = Color.fromKeyword White)
)

In [ ]:
contour3

Out[ ]: