Python 在给定顶点i的pylab中绘制三维曲面

Python 在给定顶点i的pylab中绘制三维曲面,python,matplotlib,3d,geometry,Python,Matplotlib,3d,Geometry,我有6个点,它们都位于球面上,是八面体的顶点。如何在三维轴上绘制球体内八面体的曲面 我有以下代码,但它没有达到我的期望: from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection import matplotlib.pyplot as plt Points=[[ 0.17770898, 0.72315927, 0.66742804], [-0.

我有6个点,它们都位于球面上,是八面体的顶点。如何在三维轴上绘制球体内八面体的曲面

我有以下代码,但它没有达到我的期望:

from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt

Points=[[ 0.17770898,  0.72315927,  0.66742804],
       [-0.65327074, -0.4196453 ,  0.63018661],
       [ 0.65382635,  0.42081934, -0.62882604],
       [-0.17907021, -0.72084723, -0.66956189],
       [-0.73452809,  0.5495376 , -0.39809158],
       [ 0.73451554, -0.55094017,  0.39617148]]

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

ax.add_collection3d(Poly3DCollection([Points]))

u = np.linspace(0, np.pi, 30)
v = np.linspace(0, 2 * np.pi, 30)

x = np.outer(np.sin(u), np.sin(v))
y = np.outer(np.sin(u), np.cos(v))
z = np.outer(np.cos(u), np.ones_like(v))

ax.plot_wireframe(x, y, z, alpha=0.3)

plt.show()

谢谢你的帮助

A
Poly3DCollection
是多边形列表,多边形是点列表,点是包含三个值的列表。因此,您应该将值列表传递给
Poly3DCollection
。更改以下代码:

ax.add_collection3d(Poly3DCollection([Points]))

补充海瑞的回答;体积是从几个多边形面的列表中构建的,每个面依次由点列表构建。(因此,如果面相邻,则每个点在列表列表中出现数次)。考虑下面的片段,其中的点已经被标记为:

from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure ()
ax = fig.add_subplot (1, 1, 1, projection = '3d', aspect = 1)

# octahedron
A = [ 0.17770898,  0.72315927,  0.66742804]
B = [-0.65327074, -0.4196453 ,  0.63018661]
C = [ 0.65382635,  0.42081934, -0.62882604]
D = [-0.17907021, -0.72084723, -0.66956189]
E = [-0.73452809,  0.5495376 , -0.39809158]
F = [ 0.73451554, -0.55094017,  0.39617148]
OCTO = [[E, A, B],
        [E, B, D],
        [E, D, C],
        [E, C, A],
        [F, A, B],
        [F, B, D],
        [F, D, C],
        [F, C, A],
]
ax.add_collection3d (Poly3DCollection (OCTO))

# sphere
u = np.linspace (0, np.pi, 30)
v = np.linspace (0, 2 * np.pi, 30)
x = np.outer (np.sin (u), np.sin (v))
y = np.outer (np.sin (u), np.cos (v))
z = np.outer (np.cos (u), np.ones_like (v))
ax.plot_wireframe (x, y, z, alpha = 0.3)

plt.show ()

你知道哪一行抛出了错误吗?请发布完整的回溯。非常感谢,这解决了错误,但我不清楚我在追求什么。请参阅我编辑的问题。此解决方案有效,但对于非常大的点集合,将导致变量
OCTO
,该变量具有重复数据。首选的解决方案是在点集合中使用整数索引。你知道怎么做吗?嘿,我,这解决了你想使用matlab面片的面和顶点的问题,尽管matplotlib中没有:
aspect=1
不受matplotlib的3d绘图支持(它从未得到过正确的支持,但最近被更改为抛出NotImplementedError)。看见