# Trouble getting started with Dierckx 2D Spline

**URL:** <https://discourse.julialang.org/t/trouble-getting-started-with-dierckx-2d-spline/54995>\
**Category:** General Usage\
**Tags:** splines\
**Created:** [February 10, 2021, 2:05pm UTC](https://discourse.julialang.org/t/trouble-getting-started-with-dierckx-2d-spline/54995 "2021-02-10T14:05:27Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [February 10, 2021, 10:02pm UTC](https://discourse.julialang.org/t/trouble-getting-started-with-dierckx-2d-spline/54995/2 "2021-02-10T22:02:42Z")

</div>

@natemcintosh, some possible issues in your two attempts. For the first: too few input points for bi-cubic (default) spline computations and possibly an inadequate error tolerance for the linear input data; for the second attempt: the sorted data defines a linear feature in the 2D plane, probably a ill-conditioned problem for 2D splines (plus the error tolerance issue).

Produced a working example below (_ps: used surface for a better display_)

```julia
using Dierckx, Plots
x = 2*rand(100); y = rand(100);
z = (x .- 1).^2 .+ y.^2
spl = Spline2D(x, y, z; kx=3, ky=3, s=1e-4)
xg = LinRange(0,2,200); yg = LinRange(0,1,200);
zspl = evalgrid(spl, xg, yg)
surface(xg, yg, zspl'; legend=:false, xl="x", yl="y", zl="z")
scatter!(x, y, z; ms=4, mc=:red, ma=0.6, title="Dierckx Spline2D",titlefont=12)
# xmesh = ones(200)'.*xg
# ymesh = yg'.*ones(200)
# scatter(xmesh, ymesh, zspl; ms=0, mc=:cyan, legend=:false)

```

![Dierckx_Spline2D](https://global.discourse-cdn.com/julialang/original/3X/9/e/9eb3102c2bf9524a8bdd91d93f0096aa7e0af413.png)

---

_[View the full topic](https://discourse.julialang.org/t/trouble-getting-started-with-dierckx-2d-spline/54995)._
