简体   繁体   English

Mayavi:如何翻转场景的Z轴?

[英]Mayavi: How can I flip the Z-axis of a scene?

I am trying to flip Z-axis in the mayavi volumetric 3D plot. 我正在尝试在mayavi体积3D图中翻转Z轴。 I figured how to rotate the camera etc, but that is not what I want. 我知道如何旋转相机等,但这不是我想要的。 I just want to flip the direction of Z-axis. 我只想翻转Z轴的方向。 Without manipulating the data itself 无需处理数据本身

#Minimum working example

import numpy as np
from mayavi import mlab

x, y, z = np.ogrid[-5:5:64j, -5:5:64j, -5:5:64j] #Generate XYZ
data = np.arange(x.shape[0])
x = x.ravel()
y = y.ravel()
z = z.ravel()
mlab.points3d(x, y, z, data) #Produce volumetric plot
mlab.axes(xlabel='X', ylabel='Y', zlabel='Z') #Display axis
mlab.orientation_axes()
mlab.show()

Could you please explain what you mean using non-symmetric data using this example. 您能否通过此示例解释使用非对称数据的含义。 Do you want negative z to be at the top side? 您是否希望负数z位于顶部? And why does rotating the camera not produce the result you want to see? 为何旋转相机不能产生想要的结果?

You can add the code from the macro editor (explained below). 您可以从宏编辑器添加代码(如下所述)。

import numpy as np
from mayavi import mlab

x, y, z = np.ogrid[-5:5:64j, -5:5:64j, -5:5:64j] #Generate XYZ
data = np.arange(x.shape[0])
x = x.ravel()
y = y.ravel()
z = z.ravel()

# Recorded script from Mayavi2
from numpy import array
try:
    engine = mayavi.engine
except (AttributeError, NameError):
    from mayavi.api import Engine
    engine = Engine()
    engine.start()
if len(engine.scenes) == 0:
    engine.new_scene()
# -------------------------------------------
scene = engine.scenes[0]
scene.scene.camera.position = [20.68813263960946, 20.334388554161922, 20.518300376103046]
scene.scene.camera.focal_point = [0.24373197555541992, 0.24373197555541992, 0.25]
scene.scene.camera.view_angle = 30.0
scene.scene.camera.view_up = [-0.41179533881878827, -0.4046701524210215, 0.81649658092772626]
scene.scene.camera.clipping_range = [15.729834995160559, 58.864284541884331]
scene.scene.camera.compute_view_plane_normal()
scene.scene.render()

mlab.points3d(x, y, z, data) #Produce volumetric plot
mlab.axes(xlabel='X', ylabel='Y', zlabel='Z') #Display axis
mlab.orientation_axes()

mlab.show()

If you really can set the view you want manually I would just do that. 如果您确实可以手动设置所需的视图,则只需执行此操作。 To get the correct coordinates to pass to mlab.view() read them from the interactive plot while rotating the scene: 若要获取正确的坐标以传递给mlab.view()请在旋转场景时从交互式绘图中读取它们:

在此处输入图片说明

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

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