Closed maucejo closed 1 year ago
The problem comes from the way Dash.jl
process the data. Instead of considering matrices as in PlotlyJS.jl
, Dash.jl
needs X,Y,Z
to be defined as Vectors of Vectors.
Here, the plot3D
function must be as follows:
function plot_3D(x, y, z)
nx = length(x)
nv = Int(round(nx./2.))
vl = range(0., 1., nv)
v = repeat(vl, 1, nx)
X = repeat(x', nv, 1)
XX = [c for c in eachcol(X)]
zmin = minimum(z)
traces = GenericTrace[]
Y = y*ones(size(X))
YY = [c for c in eachcol(Y)]
# Line
trace = scatter3d(x = x,
y = Y[1, :],
z = z,
mode = "lines",
line = attr(color = :blue),
showlegend = false)
# Surface
Z = zmin .+ (repeat(z', nv, 1) .- zmin).*v
ZZ = [c for c in eachcol(Z)]
surf = surface(x = XX,
y = YY,
z = ZZ,
showscale = false)
append!(traces, [trace, surf])
# Define the layout
layout = Layout(scene = attr(
xaxis = attr(autorange = "reversed")))
p = plot(traces, layout)
figure = (data = getfield.(p.plot.data, :fields), layout = p.plot.layout.fields)
return figure
end
thanks for writing down the workaround @maucejo :clap:
Hi all, I am trying to develop a Dash app containing a 3d plot. This plot includes a 3d line and a 3d plane surface. The MWE below gives you a basic overview of the app.
This app throws the following error
cwise: Arrays do not all have the same shape!
.The problem seems to be related to the definition of surface, because plotting only the 3d line works. Moreover, the function
plot_3D
works fine when usingPlotlyJS
.Thanks for your help.