Python 如何为matplotlib plot_trisurf中的单个元素着色
我有一个三角形的曲面网格,通过移动立方体生成。我想根据绘图中的任意变量为曲面元素着色。我目前正在使用plot_trisurf,但当我阅读文档时,看起来颜色总是基于Z分量,或者一个常量?我可以不为每个元素指定颜色吗?还是有更好的绘图例程可供使用?例如,下面代码中的某些内容就是我想要的,其中颜色基于行进立方体的“值”输出。谢谢Python 如何为matplotlib plot_trisurf中的单个元素着色,python,matplotlib,Python,Matplotlib,我有一个三角形的曲面网格,通过移动立方体生成。我想根据绘图中的任意变量为曲面元素着色。我目前正在使用plot_trisurf,但当我阅读文档时,看起来颜色总是基于Z分量,或者一个常量?我可以不为每个元素指定颜色吗?还是有更好的绘图例程可供使用?例如,下面代码中的某些内容就是我想要的,其中颜色基于行进立方体的“值”输出。谢谢 import numpy as np import matplotlib.pyplot as plt from skimage import measure from sk
import numpy as np
import matplotlib.pyplot as plt
from skimage import measure
from skimage.draw import ellipsoid
from matplotlib import cm
# Generate a level set about zero of two identical ellipsoids in 3D
ellip_base = ellipsoid(6, 10, 16, levelset=True)
# Use marching cubes to obtain the surface mesh of these ellipsoids
verts, faces, normals, values = measure.marching_cubes_lewiner(ellip_double, 0)
fig = plt.figure(figsize=(20, 10))
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(verts[:, 0], verts[:,1], verts[:, 2], triangles=faces, cmap=cm.rainbow, color=values)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")
ax.set_xlim(0, 24)
ax.set_ylim(0, 20)
ax.set_zlim(0, 32)
plt.tight_layout()
plt.show()
正如JohanC所指出的,事实发生后,他们重新设置了面部颜色。这对我很有用,因为我已经定义了一系列颜色
# set the face colors of the Poly3DCollection
p3dc.set_fc(colors)
也许这与此有关?这似乎暗示了ax.plot\u trisurf(..,facecolors=cmap(norm(values))。还要注意,matplotlib仅具有有限的3D功能。你可能想看看例如Mayavi。在那里挖掘,他们没有在命令中指定颜色,但你显然可以在事后设置它。我会发布答案,谢谢!