# Interpolate 3d grid of datapoints

**URL:** <https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485>\
**Category:** Visualization\
**Tags:** plotting, interpolations\
**Created:** [September 20, 2021, 4:59pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485 "2021-09-20T16:59:07Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 20, 2021, 4:59pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/1 "2021-09-20T16:59:07Z")

</div>

Hi,

Is there any package in Julia for interpolating a 3d grid of datapoints (a typical cloud of non-regularly spaced datapoints)? I need it for plotting purposes only and I do not have a specific algorithm in mind.

Thanks!

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 20, 2021, 5:46pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/2 "2021-09-20T17:46:12Z")

</div>

There are several packages, e.g. [https://github.com/SciML/Surrogates.jl](https://github.com/SciML/Surrogates.jl), [https://github.com/markmbaum/BasicInterpolators.jl](https://github.com/markmbaum/BasicInterpolators.jl), [https://github.com/RJDennis/ChebyshevApprox.jl](https://github.com/RJDennis/ChebyshevApprox.jl), [https://github.com/stevengj/FastChebInterp.jl](https://github.com/stevengj/FastChebInterp.jl) … most of these do some kind of fit, however, and do not guarantee the fit will go exactly through your original data points (unless they lie at special points, e.g. Chebyshev nodes)

If you want exact interpolation from an arbitrary set of points in 3d, one typically first forms a Delaunay triangularization (tetrahedralization in 3d) of your points, and then does (e.g.) linear interpolation within each simplex (tetrahedron). There are Julia packages for Delaunay triangulation, but I don’t know whether the whole interpolation pipeline is available. You could always call [`scipy.interpolate.LinearNDInterpolator`](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.LinearNDInterpolator.html) from Julia via PyCall, however.

(What is the source of your data points?)

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [September 20, 2021, 6:34pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/3 "2021-09-20T18:34:32Z")

</div>

How irregular and what kind of interpolation did you have in mind?

---

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 21, 2021, 12:50pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/4 "2021-09-21T12:50:16Z")

</div>

Thank you both. I am not a domain expert and thus I really have no preferences on the interpolation method to use for this graphical representation. The (x,y) coordinates are drawn at random (uniformly) and the z coordinate is a function of x and y.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 21, 2021, 1:43pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/5 "2021-09-21T13:43:22Z")

</div>

Could you show how the input data looks like or just share a representative portion of it?

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [September 21, 2021, 6:19pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/6 "2021-09-21T18:19:37Z")

</div>

Besides what stevengj mentioned above, you may also be interested in  
[https://github.com/eljungsk/ScatteredInterpolation.jl](https://github.com/eljungsk/ScatteredInterpolation.jl)

---

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 22, 2021, 4:00am UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/7 "2021-09-22T04:00:29Z")

</div>

Thank you, it looks quite intuitive. I will definitely take a look. I have also seen several applications of regression trees for spatial interpolation, so I might try that as well and see what happens. Unfortunately I cannot share the data in this instance.

---

<div class="post-metadata">

**Author:** ![fipelle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fipelle/32/4772_2.png) [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Post date:** [September 22, 2021, 8:34pm UTC](https://discourse.julialang.org/t/interpolate-3d-grid-of-datapoints/68485/8 "2021-09-22T20:34:22Z")

</div>

I managed to get the results that I wanted gridding the data via bagging (bootstrap aggregating) and plotting it with PGFPlotsX as a filled contour. I will post some code on my GitHub page for those who are interested!
