Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何绘制具有非恒定半径的圆柱体_Python_Matplotlib - Fatal编程技术网

Python 如何绘制具有非恒定半径的圆柱体

Python 如何绘制具有非恒定半径的圆柱体,python,matplotlib,Python,Matplotlib,我已经编写了生成具有固定半径的圆柱体的代码: import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from math import sin, cos, pi fig = plt.figure() ax = fig.add_subplot(111, projection='3d') theta = np.linspace(-2*pi,2*pi, 600)

我已经编写了生成具有固定半径的圆柱体的代码:

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

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

theta = np.linspace(-2*pi,2*pi, 600)
Z = np.linspace(0,1,700)

Z,theta = np.meshgrid(Z, theta)

R = 0.1
X = (R*np.cos(theta))
Y = (R*np.sin(theta))

ax.plot_surface(X,Y,Z,linewidth = 0,facecolor = 'r', shade = True, alpha = 0.6)
plt.show()

如何更改此设置,使圆柱体半径可以变化。例如,半径从圆柱体一端的0.1开始,绘制的每个连续“圆”的半径比之前多0.01?换句话说,我想把不同半径的圆“连接”在一起,形成一个半径不恒定的圆柱体。

Changed
R=np.linspace(0,1700)


您还可以尝试使用类似于
R=np.sin(np.linspace(0,1700)*4)+1的函数,谢谢!我很快就会接受(一旦时间限制达到)Nice,然后你只需添加到R中,比如
R=np.linspace(0,1700)+2
,以使圆锥体打开。顺便说一句,当我试图解决这个问题时,我做了
R=np.arange(0600*700)。重塑(600700)
:D有趣的结果
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from math import sin, cos, pi

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

theta = np.linspace(-2*pi,2*pi, 600)
Z = np.linspace(0,1,700)

Z,theta = np.meshgrid(Z, theta)

R = np.linspace(0,1,700)
X = (R*np.cos(theta))
Y = (R*np.sin(theta))

ax.plot_surface(X,Y,Z,linewidth = 0,facecolor = 'r', shade = True, alpha = 0.6)
plt.show()