This post assumes you are already familiar using Plotly.NET. If you want to manually define the position of individual plots and have special needs for axis stylings, keep on reading.
Note: There may be other ways to obtain the result seen below
First let us define three simple charts and combine them to a chart grid
#r "nuget: Plotly.NET.Interactive, 4.2.1"
open Plotly.NET
open Plotly.NET.StyleParam
open Plotly.NET.LayoutObjects
let chartA = Chart.Point(xy=[1,2])
let chartB = Chart.Point(xy=[1,2])
let chartC = Chart.Line(xy=[1,2;2,3])
[
chartA
chartB
chartC
]
|> Chart.Grid(2,2)
Loading extensions from `C:\Users\bvenn\.nuget\packages\plotly.net.interactive\4.2.1\interactive-extensions\dotnet\Plotly.NET.Interactive.dll`
Now lets define the regions the plots should be drawn in. Therefore it is required to assign unique axis ids to each chart. The resulting chart does not change by simply defining these ids:
let chartWithAxisIds =
[
chartA |> Chart.withAxisAnchor(X=1,Y=1)
chartB |> Chart.withAxisAnchor(X=2,Y=2)
chartC |> Chart.withAxisAnchor(X=3,Y=3)
]
|> Chart.Grid(2,2)
chartWithAxisIds
The defined axis identifiers can be used to set regions the charts are drawn in. Therefore, the ids are used to define the domain region of each axis.
chartWithAxisIds
|> Chart.withXAxis(
// define the axis you want to style
Id = SubPlotId.XAxis 1,
// initialize a LinearAxis
xAxis =
LinearAxis.init(
// define the range the chart should be drawn in (percentage)
// plot 1 x axis ranges from 0% to 33% of the canvas
Domain = Range.MinMax (0.00, 0.33)
)
)
The same procedure is performed for all x and y axis:
let chartsWithDefinedRegions =
chartWithAxisIds
|> Chart.withXAxis(Id = SubPlotId.XAxis 1, xAxis = LinearAxis.init(Domain = Range.MinMax (0.00, 0.33)))
|> Chart.withYAxis(Id = SubPlotId.YAxis 1, yAxis = LinearAxis.init(Domain = Range.MinMax (0.00, 0.45)))
|> Chart.withXAxis(Id = SubPlotId.XAxis 2, xAxis = LinearAxis.init(Domain = Range.MinMax (0.00, 0.33)))
|> Chart.withYAxis(Id = SubPlotId.YAxis 2, yAxis = LinearAxis.init(Domain = Range.MinMax (0.55, 1.00)))
|> Chart.withXAxis(Id = SubPlotId.XAxis 3, xAxis = LinearAxis.init(Domain = Range.MinMax (0.40, 1.00)))
|> Chart.withYAxis(Id = SubPlotId.YAxis 3, yAxis = LinearAxis.init(Domain = Range.MinMax (0.10, 0.90)))
chartsWithDefinedRegions
Much more styling can be applied to the axis.
TickVals = [1.; 1.29; 1.5; 2.; 3.]
defines the exact tick values (blue chart y axis)TickVals = []
no tick marks are visible (red chart x axis)TickFont = Font.init(Size=20,Family=FontFamily.Consolas)
sets the tick font to the specied styleNTicks = 13
sets how many tick marks are visible (green chart x axis)RangeMode = RangeMode.ToZero
the axis should span the zero value (green chart y axis)Further style options can be seen at plotly.net. The final chart generation looks like this:
[
Chart.Point(xy=[1,2]) |> Chart.withAxisAnchor(X=1,Y=1)
Chart.Point(xy=[1,2]) |> Chart.withAxisAnchor(X=2,Y=2)
Chart.Line(xy=[1,2;2,3]) |> Chart.withAxisAnchor(X=3,Y=3)
]
|> Chart.Grid(2,2)
|> Chart.withXAxis(Id = SubPlotId.XAxis 1, xAxis = LinearAxis.init(Domain = Range.MinMax (0.00, 0.33),Title=Title.init "blue x axis"))
|> Chart.withYAxis(Id = SubPlotId.YAxis 1, yAxis = LinearAxis.init(Domain = Range.MinMax (0.00, 0.45),TickVals = [1.;1.29;1.5;2.;3.]))
|> Chart.withXAxis(Id = SubPlotId.XAxis 2, xAxis = LinearAxis.init(Domain = Range.MinMax (0.00, 0.33),TickVals = []))
|> Chart.withYAxis(Id = SubPlotId.YAxis 2, yAxis = LinearAxis.init(Domain = Range.MinMax (0.55, 1.00),TickFont=Font.init(Size=20,Family=FontFamily.Consolas)))
|> Chart.withXAxis(Id = SubPlotId.XAxis 3, xAxis = LinearAxis.init(Domain = Range.MinMax (0.40, 1.00),NTicks=13))
|> Chart.withYAxis(Id = SubPlotId.YAxis 3, yAxis = LinearAxis.init(Domain = Range.MinMax (0.10, 0.90),RangeMode=RangeMode.ToZero))
|> Chart.withLegendStyle(Orientation=Orientation.Horizontal)
|> Chart.withLayoutStyle(Font=(Font.init(Family=FontFamily.Arial,Size=14)))