import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
from math import exp,sin,cos
from pylab import *
mpl.rcParams['legend.fontsize'] = 10
fig = plt.figure()
ax = fig.gca(projection='3d')
a=0.05
b=0.10
# took the liberty of reducing the max value for th
# as it was giving you values of the order of e42
th=np.linspace(0, 50, 10000)
x=a*exp(b*th)*cos(th)
y=a*exp(b*th)*sin(th)
z=np.linspace(0,2, 10000) # creating the z array with the same length as th
ax.plot(x, y, z) # adding z as an argument for the plot
ax.legend()
plt.show()
由于螺旋线的95%的点都集中在绘图中间的一个点上,因此将绘制范围限制为类似
然后使用z值的线性范围,只需在绘图函数
^{pr2}$plot(x,y,z)
中指定该范围,就可以在绘图中直接得到所需的曲线。在注意,我清理了这里的进口。E、 g.如果您从
math
导入cos
,但随后将pylab中的所有(*
)导入到命名空间中,则使用的函数cos
是numpycos
函数,而不是math中的函数(math cos函数在这里无论如何都不起作用)。总的来说:不要使用pylab。在拿哪一个取决于你。从情节本身很难说,但我的猜测是它是线性的(最简单的选择)。在
使用您的代码并添加
z
轴,您可以这样做您可以使用
a
和b
参数来获得所需的椭圆形。您还可以使用z
的定义,使其增长为指数或对数。。或者完全是别的什么。在顺便说一句,您的导入有点多余,可能一个包中的某些函数被另一个包跟踪了。在
相关问题 更多 >
编程相关推荐