Convert scatter to surface

Hello there :smiley:

I have data that can be plotted as scatter (GLMakie). I would like to convert the scatter into a surface. I tried to interpolate the data as following but it does not work (probably because of the way I use interpolate). Could you help ? Thanks :smiley:

fig = Figure(size=(1200, 400))
axs = Axis3(fig[1,1])
hm = scatter!(axs, X_plan, Y_plan, palier_2)
fig

function meshgrid(x, y)
    X = repeat(x', length(y), 1)
    Y = repeat(y, length(x), 1)
    return X, Y
end

# Define the grid to interpolate 
x_range = range(minimum(X_plan), stop=maximum(X_plan), length=50)
y_range = range(minimum(Y_plan), stop=maximum(Y_plan), length=50)

# Create a grid for evaluation
X_grid, Y_grid = meshgrid(x_range, y_range)

# Perform the interpolation
itp = interpolate(X_plan, Y_plan, palier_2, Gridded(Linear()))

Z_grid = [itp(x, y) for (x, y) in zip(X_grid, Y_grid)]

# Plot the interpolated surface
fig = Figure(size=(1200, 400))
axs = Axis3(fig[1, 1])
surface!(axs, X_grid, Y_grid, Z_grid, color = :viridis)
fig

There are multiple posts here on discourse about interpolation. Please search more and you will find an answer.

Can you please provide the full example with the definitions of arrays X_plan, Y_plan, and palier_2. I guess, that if palier_2 is an ordinary three dimensional array, then you do not need to do any interpolation.

In fact, palier_2 is not an ordinary three dimensional array :

julia> typeof(X_plan)
Vector{Float64} (alias for Array{Float64, 1})
julia> size(X_plan)
(1203,)

julia> typeof(Y_plan)
Vector{Float64} (alias for Array{Float64, 1})
julia> size(Y_plan)
(1203,)

typeof(palier_2)
Vector{Float64} (alias for Array{Float64, 1})
julia> size(palier_2)
(1203,)

You will get more help if your example code is runnable, complete with all variable definitions

I mean your code in your first post should actually define example data that someone can use, and should also bring in the necessary packages via using. It will make it more likely that someone will give their time to help you.

At a very basic level, why do you want to interpolate for surface? Isn’t a linear interpolation what surface does by default anyway?

E.g. adapting the example from the docs to a very coarse grid:

julia> surface(1:10, 1:10, [cos(x) * sin(y) for x in 1:10, y in 1:10], axis = (type=Axis3,))

image