Skip to content

Add missing 3D charts and related layout options #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Aug 23, 2021
Merged

Add missing 3D charts and related layout options #125

merged 21 commits into from
Aug 23, 2021

Conversation

kMutagene
Copy link
Collaborator

@kMutagene kMutagene commented Aug 14, 2021

This PR adds the 4 missing 3D charts, related Trace objects and layout objects such as the Scene (or adding full support, some are partially there already)

  • Add missing params:
    • Scatter3d
    • Surface
    • Mesh3d
  • Chart.Point3d (based on existing Scatter3d)
  • Chart.Line3d (based on existing Scatter3d)
  • Chart.Spline3d (based on existing Scatter3d)(seems not to be possible: Interpolation for 3d data in plotly plotly.py#423)
  • Chart.Bubble3d (based on existing Scatter3d)
  • Chart.Cone
  • Chart.StreamTube
  • Chart.Volume
  • Chart.IsoSurface
  • Full Scene param support
  • Chart.withScene to set a 3D scene
  • Full ColorAxis support
  • Full ColorBar support
  • Rework of SubplotID to cover all types of subplots
  • Tests
  • Docs

closes #126
closes #127
closes #128
closes #129
closes #130
closes #131

@kMutagene
Copy link
Collaborator Author

A few charts as a preview:

  • Cone:
Chart.Cone(
    x = [1; 1; 1],
    y = [1; 2; 3],
    z = [1; 1; 1],
    u = [1; 2; 3],
    v = [1; 1; 2],
    w = [4; 4; 1]
)

image

  • StreamTube:
let tubeData =
    Http.RequestString @"https://raw.githubusercontent.com/plotly/datasets/master/streamtube-wind.csv"
    |> Frame.ReadCsvString

Chart.StreamTube(
    x = (tubeData.["x"] |> Series.values),
    y = (tubeData.["y"] |> Series.values),
    z = (tubeData.["z"] |> Series.values),
    u = (tubeData.["u"] |> Series.values),
    v = (tubeData.["v"] |> Series.values),
    w = (tubeData.["w"] |> Series.values),
    Starts = 
        StreamTubeStarts.init(
            X = Array.init 16 (fun _ -> 80),
            Y = [20;30;40;50;20;30;40;50;20;30;40;50;20;30;40;50],
            Z = [0;0;0;0;5;5;5;5;10;10;10;10;15;15;15;15]
        ),
    ColorScale = StyleParam.Colorscale.Viridis
)

image

  • Volume:
let linspace (min,max,n) = 
    if n <= 2 then failwithf "n needs to be larger then 2"
    let bw = float (max - min) / (float n - 1.)
    Array.init n (fun i -> min + (bw * float i))

let mgrid (min,max,n) = 

    let data = linspace(min,max,n)

    let z = [|for i in 1 .. n do [|for i in 1 .. n do yield data|]|]
    let x = [|for i in 1 .. n do [|for j in 1 .. n do yield [|for k in 1 .. n do yield data.[i-1]|]|]|]
    let y = [|for i in 1 .. n do [|for j in 1 .. n do yield [|for k in 1 .. n do yield data.[j-1]|]|]|]

    x,y,z
let x,y,z = 
    mgrid(-8.,8.,40)
    |> fun (x,y,z) ->
        (x |> Array.concat |> Array.concat),
        (y |> Array.concat |> Array.concat),
        (z |> Array.concat |> Array.concat)

let values = 
    Array.map3 (fun x y z ->
        sin(x*y*z) / (x*y*z)
    ) x y z
        

Chart.Volume(
   x, y, z, values,
   Opacity=0.1,
   Surface=(Surface.init(Count=17)),
   IsoMin=0.1,
   IsoMax=0.8,
   ColorScale = StyleParam.Colorscale.Viridis

)

image

  • IsoSurface:
let xIso,yIso,zIso = 
    mgrid(-5.,5.,40)
    |> fun (x,y,z) ->
        (x |> Array.concat |> Array.concat),
        (y |> Array.concat |> Array.concat),
        (z |> Array.concat |> Array.concat)

let valueIso =
    Array.map3 (fun x y z ->
        x * x * 0.5 + y * y + z * z * 2.
    ) xIso yIso zIso
        

Chart.IsoSurface(
    xIso,yIso,zIso,valueIso,
    IsoMin = 10.,
    IsoMax = 40.,
    Caps = Caps.init(
        X = (CapFill.init(Show=false)),
        Y = (CapFill.init(Show=false))
    ),
    Surface = Surface.init(Count=5),
    ColorScale = StyleParam.Colorscale.Viridis
)

image

@kMutagene kMutagene added this to the 2.0 milestone Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3D Scene Isosurface Volume Streamtube Cone (reference)
1 participant