我正在尝试使用SymPy-Python 3.7绘制以下螺旋线:
这是我尝试过的:
import sympy as sp
from IPython.display import display
sp.init_printing()
bfi = sp.Matrix([1,0,0])
bfj = sp.Matrix([0,1,0])
bfk = sp.Matrix([0,0,1])
a = sp.symbols('a', positive=True)
b = sp.symbols('b', positive=True)
s = sp.symbols('s', real=True)
r1 = sp.cos(s/sp.sqrt(a**2+b**2))
r2 = sp.sin(s/sp.sqrt(a**2+b**2))
r3 = b*s/sp.sqrt(a**2+b**2)
r = sp.Matrix([a*r1*bfi, a*r2*bfj, r3*bfk])
v = sp.diff(r, s)
vb = v.subs(b, 3)
vab = vb.subs(a, 4)
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook
ss = np.linspace(0,10*np.pi, 100) #the domain the parameter will run on is [0, 10pi].
xmarks = sp.lambdify(s, vab[0], "numpy")(ss)
ymarks = sp.lambdify(s, vab[1], "numpy")(ss)
zmarks = sp.lambdify(s, vab[2], "numpy")(ss)
fig = plt.figure() #it is time to plot it
ax = fig.gca(projection='3d')
ax.plot(xmarks,ymarks,zmarks)
plt.show()
但是出现以下错误:
'x和y必须具有相同的第一尺寸,但形状为(100L,)和(1L,)'
我不知道如何解决。
此外,我确信必须有一种简化整个代码的方法。