Source code for curve
# -*- coding: utf-8 -*-
r"""Plot a curve in three-dimensions.
"""
import numpy as np
import matplotlib.pyplot as plt
[docs]
def curve(x, y, z, t_range):
r"""Plot a curve in three-dimensions.
:param x: the :math:`x(t)` parametric function.
:param y: the :math:`y(t)` parametric function.
:param z: the :math:`z(t)` parametric function.
:param t_range: the range of the parameter :math:`t`.
"""
ax = plt.figure().add_subplot(projection='3d')
t = np.linspace(t_range[0], t_range[1], 1000)
x_values = x(t)
y_values = y(t)
z_values = z(t)
ax.plot(x_values, y_values, z_values, label='parametric curve')
ax.legend()
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
if __name__ == '__main__':
a = 1
b = 1
w = 2 * np.pi
def x(t): # the parametric function x(t)
return a * np.cos(w * t)
def y(t): # the parametric function y(t)
return a * np.sin(w * t)
def z(t): # the parametric function z(t)
return b * t
curve(x, y, z, [0, 3])