Skip to content

Site does not accept the following snipset (error: Multiple references to 'FSharp.Core.dll' are not permitted) #92

@psiLearn

Description

@psiLearn

With nuget reference: FSharp.Plotly

open FSharp.Plotly

let rec transpose matrix : ('a [] [] )= 
  match matrix |> Array.toList with   // matrix is a list<list<int>>
  | row::rows ->      // case when the list of rows is non-empty
    match row |> Array.toList with    // rows is a list<int>
    | col::cols ->    // case when the row is non-empty
      // Take first elements from all rows of the matrix
      let first = Array.map Array.head matrix
      // Take remaining elements from all rows of the matrix
      // and then transpose the resulting matrix
      let rest = transpose (Array.map Array.tail matrix) |> Array.toList
      first :: rest
      |> List.toArray
    | _ -> [||]
  | _ -> [||] 

// Plot the data
let scatterPlotBox (title:string, inputs:float [] [],labels : string [] option, groupOpt : 'a [] option ) = 
    if inputs.Length = 0 then
        Chart.Pie([0.])
    else
        // group data by group id
        let pointsArray = 
            match groupOpt with 
            | None ->
                [|inputs|]
            | Some groupID ->
                    (inputs,groupID) 
                    ||> Array.zip
                    |> Array.groupBy snd
                    |> Array.map (fun (_,grps) ->
                        grps |> Array.map (fun gr -> gr |> fst) |> transpose
                         )
        
        let tranInput = transpose inputs
        let plotSubplot (pa:float [][]) ix iy = 
            let x = pa.[ix]
            let y = pa.[iy]
            Chart.Scatter (x,y,StyleParam.Mode.Markers) 
        let n = inputs.[0].Length  

        let idPlot i= 
            match groupOpt with 
            | None ->
                Chart.Violin ((tranInput).[i],Points=StyleParam.Jitterpoints.All)
                //Chart.BoxPlot((transpose inputs).[i],Jitter=0.1,Boxpoints=StyleParam.Boxpoints.All)
            | Some outputs ->
                Chart.Violin (outputs |> Array.map (string),(tranInput).[i],Points=StyleParam.Jitterpoints.All)
                //Chart.BoxPlot(outputs |> Array.map (string),(transpose inputs).[i],Jitter=0.1,Boxpoints=StyleParam.Boxpoints.All)
        // create subplots
        [   for i=0 to n-1 do 
                for j=0 to n-1 do 
                    let addYLable = 
                        if j = 0 && Option.isSome labels && labels.Value.Length > i then
                            Chart.withY_AxisStyle(labels.Value.[i]) 
                        else    
                            id                                
                    let addXLable = 
                        if i = n-1 && Option.isSome labels && labels.Value.Length > j then
                            Chart.withX_AxisStyle(labels.Value.[j]) 
                        else    
                            id                                
                    let pl = 
                        if i <> j then 
                            [ for pa in pointsArray do
                                        yield plotSubplot pa j i
                            ]   |> Chart.Combine                    
                        else
                            idPlot i
                    yield pl                    
                            |> addYLable
                            |> addXLable                
        ]
        |> Chart.Stack(Columns=n,Space=0.05)
        |> Chart.withTitle(title)
        |> Chart.withLegend(false)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions