如何围绕列表给出的曲线绘制螺旋线?

问题描述

如何围绕列表给出的橙色曲线绘制螺旋线?方位角、仰角和 figsize 设置为所需的结果。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from numpy import sin,cos

A = [-0.1646169553829357,-0.18045534297929358,-0.19607272004818602,-0.211354488132617,-0.22616904489940454,-0.24036624624003963,-0.25377639986609546,-0.26621030641288784,-0.27746107555189253,-0.287309176814374,-0.2955313683720342,-0.3019143406048014,-0.3062726740423563]
B = [0.13385167110565344,0.13161004556697875,0.12815132761818687,0.1234273074581178,0.11739746666382476,0.11003213593352616,0.10131707253912245,0.09125949610772532,0.07989522181968708,0.06729724452652447,0.053583847907859236,0.038924841462667246,0.023542804704085943]

# Plot figure with size
figsize=(10,5)
fig = plt.figure(figsize=figsize)

# Axes 
ax = fig.gca(projection = '3d')
azimuth=90
elevation=90
ax.azim = azimuth    # y rotation (default=270)
ax.elev = elevation  # x rotation (default=0)

r = 0.1
c = 0.5
t = np.linspace(0,5000,100)

# parametric equation of a helix
x = r*cos(t)
y = r*sin(t)
z = c*t
ax.plot(x,y,z,zdir='z',lw=2)
ax.plot(A,B)
plt.show()

enter image description here

所需的结果是穿过螺旋中心的橙色曲线。

enter image description here

解决方法

能否请您详细说明或在曲线中添加更多细节?

from mpl_toolkits.mplot3d import Axes3D  

import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator,FormatStrFormatter
import numpy as np


fig = plt.figure()
ax = fig.gca(projection='3d')

u=np.linspace(0,4*np.pi,50);
v=np.linspace(0,2*np.pi,50);
u,v=np.meshgrid(u,v) ;
x=(1.2+0.5*np.cos(v))*np.cos(u);
y=(1.2+0.5*np.cos(v))*np.sin(u);
z=0.5*np.sin(v)+u/np.pi;

# Plot the surface.
surf = ax.plot_surface(x,y,z,cmap=cm.jet,linewidth=0,antialiased=False)
#plot the 3d line
u = np.linspace(0,40)
x=1.2*np.cos(u);
y=1.2*np.sin(u);
z=u/np.pi;
ax.plot(x,'b');

enter image description here

fig = plt.figure()
ax = fig.gca(projection='3d')

u=np.linspace(0,v) ;
x=(1.2+0.5*np.cos(v))*np.cos(u);
y=(1.2+0.5*np.cos(v))*np.sin(u);
z=0.5*np.sin(v)+u/np.pi;

# Plot a basic wireframe.
ax.plot_wireframe(x,cmap=cm.viridis,rstride=1,cstride=1)

#plot the 3d line
u = np.linspace(0,'b');

enter image description here

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...