Plotly.NET icon indicating copy to clipboard operation
Plotly.NET copied to clipboard

Multiple Y-Axes with Subplots positioning

Open MaheshPunna opened this issue 4 years ago • 2 comments


open Plotly.NET

let x = [for i in 0..10 -> i]
let y = [for i in x -> Math.Pow(float i,2.0)]
let y2 = [for i in x -> Math.Pow(float i,3.0)]

[
    [
        Chart.Point(x,y,Name="1,1") |> Chart.withAxisAnchor(Y=1) 
        Chart.Point(x,y2,Name="1,2") |> Chart.withAxisAnchor(Y=2) 
    ]|>
    Chart.combine
    |> Chart.withYAxisStyle("y1",Side=StyleParam.Side.Left,Id=StyleParam.SubPlotId.YAxis 1)    
    |> Chart.withYAxisStyle("y2", Side=StyleParam.Side.Right,Id=StyleParam.SubPlotId.YAxis 2)
    Chart.Invisible()

]
|> Chart.Grid(2,2)

image

How can I make y2 axis attached to the plot??

MaheshPunna avatar Sep 01 '21 04:09 MaheshPunna

Chart.Grid assigns new axis anchors, so it is currently not possible to do what you are aiming for with it. You can however create the grid manually using the SubPlots parameter like this:

let x = [for i in 0..10 -> i]
let y = [for i in x -> Math.Pow(float i,2.0)]
let y2 = [for i in x -> Math.Pow(float i,3.0)]

let myChart = 
    [
        Chart.Point(x,y,Name="1,1") |> Chart.withAxisAnchor(Y=1) 
        Chart.Point(x,y2,Name="1,2") |> Chart.withAxisAnchor(Y=2) 
    ]
    |> Chart.combine
    |> Chart.withYAxisStyle("y1",Side=StyleParam.Side.Left,Id=StyleParam.SubPlotId.YAxis 1)    
    |> Chart.withYAxisStyle("y2", Side=StyleParam.Side.Right,Id=StyleParam.SubPlotId.YAxis 2)

let chartGrid =
    LayoutGrid.init(
        Rows = 1,
        Columns = 2,
        SubPlots = [|
            [|
                StyleParam.LinearAxisId.X 1, StyleParam.LinearAxisId.Y 1
                StyleParam.LinearAxisId.X 1, StyleParam.LinearAxisId.Y 2
            |]
        |]
    )

[
    myChart
    Chart.Invisible()
]
|> Chart.combine
|> Chart.withLayoutGrid chartGrid
|> Chart.show

image

kMutagene avatar Sep 02 '21 08:09 kMutagene

@kMutagene why Plot "1,1" is not being shown?

MaheshPunna avatar Oct 06 '21 03:10 MaheshPunna