Plot CSV Data in F#
How to create charts from csv files with Plotly and F#
In [1]:
#r "nuget: Plotly.NET, 2.0.0-preview.8"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.8"
#r "nuget: FSharp.Data"
#r "nuget:Deedle"
Plot from CSV with Plotly¶
In [2]:
open FSharp.Data
open Deedle
open Plotly.NET
open Plotly.NET.LayoutObjects
let dataset =
Http.RequestString "https://raw.githubusercontent.com/plotly/datasets/master/2014_apple_stock.csv"
|> fun csv -> Frame.ReadCsvString(csv,true,separators=",")
let getColumn column=
dataset
|> Frame.getCol column
|> Series.values
let xy = Seq.zip (getColumn "AAPL_x" :> seq<DateTime>) (getColumn "AAPL_y" :> seq<float>)
Chart.Line(xy,Name="Share Prices (in USD)")
|>Chart.withLayout(Layout.init(Title.init("Apple Share Prices over time (2014)"),PlotBGColor=Color.fromString "#e5ecf6",ShowLegend=true,Width=1100))
|>Chart.withXAxis(LinearAxis.init(Title=Title.init("AAPL_x"),ZeroLineColor=Color.fromString"#ffff",ZeroLineWidth=2.,GridColor=Color.fromString"#ffff" ))
|>Chart.withYAxis(LinearAxis.init(Title=Title.init("AAPL_y"),ZeroLineColor=Color.fromString"#ffff",ZeroLineWidth=2.,GridColor=Color.fromString"#ffff" ))
Out[2]: