如果我使用mayavi的contour3d选项绘制三维数据,则有3个默认轮廓,但它们的间距如何。我知道轮廓的数量可以改变,但它们可以是用户指定的值(我肯定会猜到这是可能的)。我想知道如何绘制默认的3个轮廓。取决于标量的最大值以及它是如何分布的。
答案 0 :(得分:1)
碰巧我遇到了同样的问题并找到了解决方案。 以下是一些示例代码:
import numpy as np
from mayavi import mlab
from mayavi.api import Engine
def fun(x, y, z):
return np.cos(x) * np.cos(y) * np.cos(z)
# create engine and assign figure to it
engine = Engine()
engine.start()
fig = mlab.figure(figure=None, engine=engine)
contour3d = mlab.contour3d(x, y, z, fun, figure=fig)
scene = engine.scenes[0]
# get a handle for the plot
iso_surface = scene.children[0].children[0].children[0]
# the following line will print you everything that you can modify on that object
iso_surface.contour.print_traits()
# now let's modify the number of contours and the min/max
# you can also do these steps manually in the mayavi pipeline editor
iso_surface.compute_normals = False # without this only 1 contour will be displayed
iso_surface.contour.number_of_contours = 2
iso_surface.contour.minimum_contour = -1.3
iso_surface.contour.maximum_contour = 1.3
现在讲述轮廓的含义。嗯,这个数字显然表明创造了多少轮廓。然后,min / max的值将定义轮廓将在其上展开的线性空间。该值应该基本上影响沿表面法线的收缩/膨胀。
编辑:这是一个提示。获得绘图窗口后,单击左上角的mayavi管道图标。在那里你可以修改你的对象(通常在树中最低)。当您按下红色记录按钮并开始修改时,它将为您提供相应的代码行。