// can't yet format YamlFrontmatter (["title: Line and scatter plots"; "category: Simple Charts"; "categoryindex: 3"; "index: 1"], 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"


# Line and scatter plots¶

Summary: This example shows how to create line and point charts in F#.

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

In [3]:
open Plotly.NET

let x  = [1.; 2.; 3.; 4.; 5.; 6.; 7.; 8.; 9.; 10.; ]
let y = [2.; 1.5; 5.; 1.5; 3.; 2.5; 2.5; 1.5; 3.5; 1.]


A line or a point chart can be created using the Chart.Line and Chart.Point functions.

## Chart.Line with LineStyle¶

The following example generates a line Plot containing X and Y values and applies a line style to it.

In [4]:
let line1 =
Chart.Line(
x,y,
Name="line",
ShowMarkers=true,
MarkerSymbol=StyleParam.MarkerSymbol.Square)
|> Chart.withLineStyle(Width=2.,Dash=StyleParam.DrawingStyle.Dot)

In [ ]:
line1

Out[ ]:

## Pipelining into Chart.Line¶

The following example calls the Chart.Line method with a list of X and Y values as tuples. The snippet generates values of a simple function, f(x)=x^2. The values of the function are generated for X ranging from 1 to 100. The chart generated is shown below.

In [6]:
let line2 =
// Drawing graph of a 'square' function
[ for x in 1.0 .. 100.0 -> (x, x ** 2.0) ]
|> Chart.Line

In [ ]:
line2

Out[ ]:

## Spline charts¶

Spline charts interpolate the curves between single points of the chart to generate a smoother version of the line chart.

In [8]:
let spline1 = Chart.Spline(x,y,Name="spline")

In [ ]:
spline1

Out[ ]:
In [10]:
let spline2 =
Chart.Spline(
x,y,
Name="spline",
Smoothing = 0.4
)


In [ ]:
spline2

Out[ ]:

## Point chart with text label¶

The following example calls the Chart.Point function to generate a scatter Plot containing X and Y values. Addtionally, text labels are added .

If TextPosition is set the labels are drawn otherwise only shown when hovering over the points.

In [12]:
let labels  = ["a";"b";"c";"d";"e";"f";"g";"h";"i";"j";]

let pointsWithLabels =
Chart.Point(
x,y,
Name="points",
MultiText=labels,
TextPosition=StyleParam.TextPosition.TopRight
)

In [ ]:
pointsWithLabels

Out[ ]: