I have a 3D scatter plot that displays a dataframe named data
.
It tipicaly generates a shape that could be fit with a single line or ellipse.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(data['x'], data['y'], data['z'], c=data['c'])
plt.show()
Typical example (sorry I cannot share my data...):
So, now I would like to compute a multivariate regression that fits this cloud of dots. There are a lot of articles explaining how to fit this with a plane, but I would like to fit it with a line.
As a bonus, I would also like to fit these dots with an ellipse. Thus, it would reflect the standard deviation and would be much more visual.