Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I plot a parametrized function in matplotlib?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading