Skip to content

Couldn't use Chart.withLayoutGridStyle to position subplots in a grid #163

@gaviei

Description

@gaviei

in the example https://plotly.com/python/pie-charts/#pie-charts-in-subplots, subplots are positioned in a grid, this behaviour could be achieved in plotly.net only by a dynamic assignment do ?domain, I tried to use Chart.withLayoutGridStyle Domain property, with Row/Column(0 and 1 base index) and X/Y, but I couldn't make it work

#r "nuget: Plotly.NET, 2.0.0-preview.7"
#r "nuget: Plotly.NET.Interactive, 2.0.0-preview.7"
open Plotly.NET

let labels = ["1st"; "2nd"; "3rd"; "4th"; "5th"]
let nightColors = ["rgb(56, 75, 126)"; "rgb(18, 36, 37)"; "rgb(34, 53, 101)"; "rgb(36, 55, 57)"; "rgb(6, 4, 4)"]
let sunflowersColors = ["rgb(177; 127; 38)"; "rgb(205; 152; 36)"; "rgb(99; 79; 37)"; "rgb(129; 180; 179)"; "rgb(124; 103; 37)"]
let irisesColors = ["rgb(33; 75; 99)"; "rgb(79; 129; 102)"; "rgb(151; 179; 100)";"rgb(175; 49; 35)"; "rgb(36; 73; 147)"]
let cafeColors =  ["rgb(146; 123; 21)"; "rgb(177; 180; 34)"; "rgb(206; 206; 40)"; "rgb(175; 51; 21)"; "rgb(35; 36; 21)"]

let layout = Layout.init(Title = Title.init(Text = "Van Gogh: 5 Most Prominent Colors Shown Proportionally"),
                          Showlegend = false,
                          Width = 1000.0,
                          Height = 500.0)
    
let starryNight = 
    let tmp = Trace("pie")
    tmp?labels <- labels
    tmp?domain <- {|x = [0.; 0.5]; y = [0.5; 1.0]|}
    tmp?name <- "Starry Night"
    tmp?marker_colors <- nightColors
    tmp?values <- [38; 27; 18; 10; 7]
    GenericChart.ofTraceObject(tmp) |> Chart.withLayoutGridStyle(Domain = Domain.init(X = StyleParam.Range.MinMax(0.0, 0.5),
                                                                                      Y = StyleParam.Range.MinMax(0.5, 1.0)))

let sunflowers = 
    let tmp = Trace("pie")
    tmp?labels <- labels
    tmp?domain <- {|x = [0.5; 1.0]; y = [0.5; 1.0]|}
    tmp?marker_colors <- sunflowersColors
    tmp?name <- "Sunflowers"
    tmp?values <- [28; 26; 21; 15; 10]
    GenericChart.ofTraceObject(tmp) |> Chart.withLayoutGridStyle(Domain = Domain.init(X = StyleParam.Range.MinMax(0.5, 1.0),
                                                                                      Y = StyleParam.Range.MinMax(0.5, 1.0)))

let irises = 
    let tmp = Trace("pie")
    tmp?labels <- labels
    tmp?domain <- {|x = [0.0; 0.5]; y = [0.0; 0.5]|}
    tmp?marker_colors <- irisesColors
    tmp?name <- "Irises"
    tmp?values <- [38; 19; 16; 14; 13]
    GenericChart.ofTraceObject(tmp) |> Chart.withLayoutGridStyle(Domain = Domain.init(Row = 2, Column = 1))

let nightCafe = 
    let tmp = Trace("pie")
    tmp?labels <- labels
    tmp?domain <- {|x = [0.5; 1.0]; y = [0.0; 0.5]|}
    tmp?marker_colors <- cafeColors
    tmp?name <- "The Night Café"
    tmp?values <- [31; 24; 19; 18; 8]
    GenericChart.ofTraceObject(tmp) |> Chart.withLayoutGridStyle(Domain = Domain.init(Row = 2, Column = 2))
    
[ starryNight; sunflowers; irises; nightCafe ]  |> Chart.Grid(2, 2)
                                                |> Chart.withLayout(layout)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: MissingAbstractionPlotly.js functionality that has to be implemented

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions