Skip to content

Latest commit

 

History

History
78 lines (64 loc) · 2.52 KB

log-plot.md

File metadata and controls

78 lines (64 loc) · 2.52 KB
jupyter
jupytext kernelspec language_info plotly
text_representation
extension format_name format_version jupytext_version
.md
markdown
1.3
1.12.0
display_name language name
.NET (F#)
F#
.net-fsharp
codemirror_mode file_extension mimetype name nbconvert_exporter pygments_lexer version
name version
ipython
3
.fs
text/x-fsharp
F#
fsharp
fsharp
5.0
description display_as language layout name order page_type permalink thumbnail
How to make Log plots in F# with Plotly.
scientific
fsharp
base
Log Plots
5
example_index
fsharp/log-plot/
thumbnail/log.jpg
#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