Log Plots in F#
How to make Log plots in F# with Plotly.
In [1]:
#r "nuget: Newtonsoft.Json, 12.0.3"
#r "nuget: Plotly.NET, 2.0.0-preview.10"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.10"
#r "nuget: FSharp.Data"
This page shows examples of how to configure 2-dimensional Cartesian axes to follow a logarithmic rather than linear progression. Configuring gridlines, ticks, tick labels and axis titles on logarithmic axes is done the same was as with linear axes.
Logarithmic Axes¶
In [2]:
open Plotly.NET
open Plotly.NET.LayoutObjects
open FSharp.Data
let data = CsvFile.Load("https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv")
let x = data.Rows |> Seq.map (fun row -> row.GetColumn("gdpPercap"))
let y = data.Rows |> Seq.map (fun row -> row.GetColumn("lifeExp"))
Chart.Scatter(x=x,y=y,mode=StyleParam.Mode.Markers )
|> Chart.withXAxis(LinearAxis.init(AxisType=StyleParam.AxisType.Log))
Out[2]:
Setting the range of a logarithmic axis works the same was as with linear axes: using the XAxis Range and YAxis Range keywords on the Layout.
In the example below, the range of the x-axis is [0, 5] in log units, which is the same as [0, 10000] in linear units.
In [3]:
open Plotly.NET
open Plotly.NET.LayoutObjects
open FSharp.Data
let data = CsvFile.Load("https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv")
let x = data.Rows |> Seq.map (fun row -> row.GetColumn("gdpPercap"))
let y = data.Rows |> Seq.map (fun row -> row.GetColumn("lifeExp"))
Chart.Scatter(x=x,y=y,mode=StyleParam.Mode.Markers )
|> Chart.withXAxis(LinearAxis.init(AxisType=StyleParam.AxisType.Log, Range=StyleParam.Range.MinMax(0.,5.))) // log range: 10^0=1, 10^5=100000
|> Chart.withYAxisStyle(title="lifeExp",MinMax=(0.,100.)) // linear range
Out[3]: