Skip to content
Advertisement

How to plot a line in 3 dimensional space with matplotlib

I have two 3D-points, for example a = (100, 100, 10) and b = (0, 100, 60), and would like to fit a line through those points. I know, the 3D line equation can have different shapes:

Vector-form:

JavaScript

Parameter-form:

JavaScript

But I have a problem getting the data in the right shape for a numerical function.

Advertisement

Answer

The following code should work

JavaScript

Here the ax.plot3D() plots a curve that joins the points (x[i], y[i], z[i]) with straight lines.

Advertisement