3D Line of Best FitΒΆ

Fit a line to multiple 3D points.

plot line 3d

Out:

(<Figure size 640x480 with 1 Axes>, <Axes3DSubplot:>)

from skspatial.objects import Line, Points
from skspatial.plotting import plot_3d


points = Points(
    [
        [0, 0, 0],
        [1, 1, 0],
        [2, 3, 2],
        [3, 2, 3],
        [4, 5, 4],
        [6, 5, 5],
        [6, 6, 5],
        [7, 6, 7],
    ],
)

line_fit = Line.best_fit(points)


plot_3d(
    line_fit.plotter(t_1=-7, t_2=7, c='k'),
    points.plotter(c='b', depthshade=False),
)

Total running time of the script: ( 0 minutes 0.141 seconds)

Gallery generated by Sphinx-Gallery