2017-08-11 266 views
4

如何使用Sympy繪製以下3D曲線(作爲示例)?我知道只是爲t創建一個數組,然後在Matplotlib中執行此操作,但我並不想繪製此曲線的,而是學習如何以符號方式定義和繪製曲線。使用Sympy在3D中繪製曲線

α(T)=(cos(t)的,罪(T),T)

from sympy import * 

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

# now what? 

我已經使用各種方式的情節方法嘗試,但此僅導致在任一三條單獨的1D曲線或錯誤。

+0

研究這個http://docs.sympy.org/latest/modules/plotting.html。 – swatchai

回答

6
之間的接口

您必須使用中的方法,你的情況你需要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的限制。

enter image description here 尋找更多的例子在3D繪圖與sympy:第一https://github.com/sympy/sympy/blob/master/examples/beginner/plot_examples.py

2

我從來沒有試圖在sympy

)ploting我懷疑更將有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() 

enter image description here