Plot CSV Data in F#
How to create charts from csv files with Plotly and F#
Plotly is known for its graphing libraries, but it's also a broader ecosystem for building interactive data apps, AI data analysis tools, and deploying and hosting Dash apps. Explore the full set of tools and platforms designed to help turn data into action. Discover Plotly.
Note: We are retiring documentation for R, MATLAB, Julia, and F#. Learn more about this change here.
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]: