简体   繁体   English

Mayavi Contour 3D

[英]Mayavi Contour 3d

If I plot a 3d data using contour3d option of mayavi, there are 3 default contours but how they spaced. 如果我使用mayavi的轮廓线3d选项绘制3d数据,则有3个默认轮廓线,但它们之间的间距是多少。 I understand the number of contours can be changed, but can they be at user specified values (I would surely guess that is possible). 我知道轮廓的数量可以更改,但是可以将其设置为用户指定的值(我肯定可以做到)。 I would like to know how are the default 3 contours drawn. 我想知道如何绘制默认的3个轮廓。 Depending on maximum value of scalar and how is it distributed. 取决于标量的最大值及其分布方式。

As it happens I just had the same problem and found a solution. 碰巧的是,我遇到了同样的问题并找到了解决方案。 Here is some sample code: 这是一些示例代码:

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

Now about the meaning of the contours. 现在介绍轮廓的含义。 Well, the number obviously says how many contours are created. 好吧,这个数字显然说明了创建了多少轮廓。 Then the values for min/max will define a linear space over which the contours will be spread. 然后,最小值/最大值的值将定义一个线性空间,轮廓将在该线性空间上展开。 The value should basically influence the shrinkage/expansion along the surface normals. 该值应基本上影响沿表面法线的收缩/扩展。

Edit: Here's a tip. 编辑:这是一个提示。 When you got your plot window, click on the mayavi pipeline icon in the top left. 到达绘图窗口后,单击左上方的mayavi管道图标。 There you can modify your object (usually lowest in the tree). 您可以在那里修改对象(通常在树中最低)。 When you press the red record button and start modifying things it will give you the corresponding lines of code. 当您按下红色的记录按钮并开始修改内容时,它将为您提供相应的代码行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM