Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: What kind of splines do we plot when using the option line_shape='spline'?

I am preparing some code to interpolate a serie of points with splines.

There are many kinds of splines: quadratic, cubic, many boundary conditions...

So far I have tried the most popular ones: cubic splines, with boundary conditions:

  • Natural: second derivative is zero at first and last points.
  • Clamped: first derivative is zero at first and last points.
  • Not-a-knot: third derivative is continuous at second and second-to-last points.

I have also tried quadratic splines with "clamped" initial condition.

I have discovered that Plotly also has a built-in interpolation function when we define the trace like this:

fig.add_trace(go.Scatter(
    x=df['timestamp'],
    y=df['values'],
    mode='lines',
    line_shape='spline',
))

This plotly's spline looks very good for my taste. It is soft and has less oscillation than, for example, the natural cubic spline:

Red line is natural cubic spline. Gray line is plotly's spline.

enter image description here

So my question is: What exact kind of spline is this?

I have tried to compare it with the curves I have mentioned above. None of them is like the Plotly's spline.

I have checked Plotly's documentation and it does not tell you what kind of curves are they using. But it says that you can add the parameter "smoothing" in order to control the curvature.

Does anyone know how the Plotly guys do it?

like image 873
eliteA92 Avatar asked Nov 06 '22 12:11

eliteA92


1 Answers

I haven't been able to find a complete description in the docs either. But by the looks of your figure, I would assume that it's some sort of Monotone cubic interpolation.

If you compare your figure to a similar figure from the source above, you'll see that the illustrated splines have quite a bit in common:

enter image description here

Judging by the areas highlighted by the grey, red and green circles, the splines applied by plotly seem to have the same smoother traits than other comparable options.

like image 198
vestland Avatar answered Nov 15 '22 06:11

vestland