使用 Sympy 绘制 3D 曲线

Plot a curve in 3D with Sympy

如何使用 Sympy 绘制以下 3D 曲线(作为示例)?我知道只需为 t 创建一个数组并在 Matplotlib 中执行此操作,但我真的不想绘制 this 曲线,而是学习如何以符号方式定义和绘制曲线。

alpha(t) = (cos(t), sin(t), t)

from sympy import *

t = symbols('t')
alpha = [cos(t), sin(t), t]

# now what?

我尝试过以各种方式使用 plot 方法,但这只会导致三个单独的一维曲线或错误。

我从未尝试过在 sympy 中密谋

估计会有更多人有matplotlib经验

lambdify()是符号表达式和正则函数的接口

from sympy import *
from sympy.utilities.lambdify import lambdify
import math

t = symbols('t')
alpha = [cos(t), sin(t), t]

f = lambdify(t, alpha)

T = [2*math.pi/100*n for n in range(100)]
F = [f(x) for x in T]

import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d

fig1, ax1 = plt.subplots(subplot_kw=dict(projection='3d'))
ax1.plot(*zip(*F))
ax1.set_aspect('equal')
plt.show()

您必须使用 sympy.plotting 中的方法,在您的情况下您需要 plot3d_parametric_line:

from sympy import *
from sympy.plotting import plot3d_parametric_line

t = symbols('t')
alpha = [cos(t), sin(t), t]
plot3d_parametric_line(*alpha)

plot3d_parametric_line(cos(t), sin(t), t, (t, 0, 2*pi))如果你想设置t的限制。

寻找更多示例以使用 sympy 在 3d 中绘制:https://github.com/sympy/sympy/blob/master/examples/beginner/plot_examples.py