打印圆锥体时断开的曲面

2024-09-28 20:48:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用python绘制曲面(z+1)²=x²+y²和4z=x²+y²。在

我写了这个代码:

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
X= np.arange(-2,3,.1)
Z=np.arange(0,2,.1)
X,Z = np.meshgrid(X,Z)
Y=np.sqrt((Z+1)**2-X**2)
Y2=np.sqrt(4*Z-X**2)
ax.plot_wireframe(X, Y, Z, rstride = 1, cstride =1)
ax.plot_wireframe(X, -Y, Z, rstride = 1, cstride =1)
ax.plot_surface(X,Y2,Z,rstride=1,cstride=1,color='red')
ax.plot_surface(X,-Y2,Z,rstride=1,cstride=1,color='red')
ax.set_zlim(0,2)

plt.show()

这必须显示两个圆锥。但是,每个圆锥体不是连续的,也就是说,有一些面缺失,我不知道为什么。任何帮助都将不胜感激。在


Tags: importplotasnpfigpltsqrtax