How do I plot such function in matplotlib? It a function that returns a point (x,y,z):
def f(t):
return (t, t+4, t)
This is supposed to describe a line in 3D space
Splitting them up into three separate component functions is not acceptable for me.
>Solution :
You don’t need to split up the function. Just use numpy to create vectors and unpack the result for the plotting.
import numpy as np
import matplotlib.pyplot as plt
plt.close("all")
def f(t):
return (t, t+4, t)
t = np.linspace(0, 10, 100)
fig, ax = plt.subplots(subplot_kw={"projection":"3d"})
ax.plot(*f(t))
ax.set(xlabel="x", ylabel="y", zlabel="z")
fig.show()
