# Convert scatter to surface

**URL:** https://discourse.julialang.org/t/convert-scatter-to-surface/119276
**Category:** Visualization
**Tags:** question, plotting, interpolations
**Created:** [September 11, 2024, 9:50am UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276 "2024-09-11T09:50:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![NaSi](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@NaSi](https://discourse.julialang.org/u/NaSi)
#### Post date: [September 11, 2024, 9:50am UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276/1 "2024-09-11T09:50:29Z")

</div>

Hello there 😃

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 😃

```julia
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

```

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [September 11, 2024, 11:00am UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276/2 "2024-09-11T11:00:40Z")

</div>

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

---

<div class="post-metadata">

### Author: ![fedoroff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fedoroff/32/53209_2.png) [@fedoroff](https://discourse.julialang.org/u/fedoroff)
#### Post date: [September 11, 2024, 11:14am UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276/3 "2024-09-11T11:14:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![NaSi](https://avatars.discourse-cdn.com/v4/letter/n/ecae2f/32.png) [@NaSi](https://discourse.julialang.org/u/NaSi)
#### Post date: [September 11, 2024, 11:22am UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276/4 "2024-09-11T11:22:25Z")

</div>

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,)

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [September 11, 2024, 11:27am UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276/5 "2024-09-11T11:27:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![DanielVandH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielvandh/32/31134_2.png) [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)
#### Post date: [September 11, 2024, 1:04pm UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276/7 "2024-09-11T13:04:19Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [September 11, 2024, 1:13pm UTC](https://discourse.julialang.org/t/convert-scatter-to-surface/119276/8 "2024-09-11T13:13:49Z")

</div>

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
julia> surface(1:10, 1:10, [cos(x) * sin(y) for x in 1:10, y in 1:10], axis = (type=Axis3,))

```

![image](https://global.discourse-cdn.com/julialang/original/3X/4/7/4753f572dd1f80e5d63a7227f5d35dddf1e7f9b6.png)
