簡體   English   中英

使用Sympy在3D中繪制曲線

[英]Plot a curve in 3D with Sympy

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

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

from sympy import *

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

# now what?

我嘗試過以各種方式使用繪圖方法,但這只會導致三條單獨的1D曲線或錯誤。

您必須使用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的限制。

在此輸入圖像描述 尋找更多的例子在3d中用sympy繪制: https//github.com/sympy/sympy/blob/master/examples/beginner/plot_examples.py

我從未嘗試過同情的情節

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

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM