Log Plots in F#
How to make Log plots in F# with Plotly.
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.
#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¶
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))
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.
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