【发布时间】:2016-05-10 18:20:37
【问题描述】:
如果我使用 mayavi 的 contour3d 选项绘制 3d 数据,则有 3 个默认等高线,但它们的间距如何。我知道轮廓的数量可以改变,但它们可以是用户指定的值吗(我肯定猜想这是可能的)。我想知道默认的 3 个轮廓是如何绘制的。取决于标量的最大值及其分布方式。
【问题讨论】:
标签: python plot contour mayavi
如果我使用 mayavi 的 contour3d 选项绘制 3d 数据,则有 3 个默认等高线,但它们的间距如何。我知道轮廓的数量可以改变,但它们可以是用户指定的值吗(我肯定猜想这是可能的)。我想知道默认的 3 个轮廓是如何绘制的。取决于标量的最大值及其分布方式。
【问题讨论】:
标签: python plot contour mayavi
碰巧我遇到了同样的问题并找到了解决方案。 下面是一些示例代码:
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
现在关于等高线的含义。好吧,这个数字显然说明了创建了多少个轮廓。然后最小值/最大值的值将定义一个线性空间,轮廓将在该空间上分布。该值应该基本上影响沿表面法线的收缩/膨胀。
编辑:这里有一个提示。当你得到你的绘图窗口时,点击左上角的 mayavi 管道图标。在那里您可以修改您的对象(通常在树中最低)。当您按下红色的记录按钮并开始修改内容时,它将为您提供相应的代码行。
【讨论】: