Mayavi:如何翻转场景的 Z 轴?
Mayavi: How can I flip the Z-axis of a scene?
我正在尝试翻转 mayavi 体积 3D 图中的 Z 轴。我想出了如何旋转相机等,但这不是我想要的。我只想翻转 Z 轴的方向。无需操作数据本身
#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()
能否请您解释一下使用此示例使用非对称数据的含义。
你想让负 z 位于顶部吗?
以及为什么旋转相机不会产生您想要看到的结果?
您可以从宏编辑器添加代码(如下所述)。
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()
如果你真的可以手动设置你想要的视图,我会这样做。
要获得传递给 mlab.view()
的正确坐标,请在旋转场景时从交互式绘图中读取它们:
我正在尝试翻转 mayavi 体积 3D 图中的 Z 轴。我想出了如何旋转相机等,但这不是我想要的。我只想翻转 Z 轴的方向。无需操作数据本身
#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()
能否请您解释一下使用此示例使用非对称数据的含义。 你想让负 z 位于顶部吗? 以及为什么旋转相机不会产生您想要看到的结果?
您可以从宏编辑器添加代码(如下所述)。
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()
如果你真的可以手动设置你想要的视图,我会这样做。
要获得传递给 mlab.view()
的正确坐标,请在旋转场景时从交互式绘图中读取它们: