简体   繁体   English

在Python脚本中设置mayaVI管道属性

[英]Set mayaVI pipeline properties in Python script

I'm using mayaVI to plot a surface and a vector field in 3D, with the functions mayavi.mlab.surf and mayavi.mlab.quiver3D. 我正在使用mayaVI在3D中绘制曲面和矢量场,使用函数mayavi.mlab.surf和mayavi.mlab.quiver3D。 These functions do not have many keyword arguments that let me modify the appearance of the surface and quivers, in comparison to the Mayavi pipeline, where I can edit things down to the most miniscule detail (for example quiver arrow head radius - see example figure below). 与Mayavi管道相比,这些函数没有很多关键字参数可以让我修改曲面和箭头的外观,我可以将其编辑到最微小的细节(例如箭头箭头半径 - 参见下面的示例图)。 The issue is that once I have made these changes in the mayaVI pipeline, there seems to be no way to save these settings until the next time I want to redraw the figure. 问题是,一旦我在mayaVI管道中进行了这些更改,似乎无法保存这些设置,直到下次我想重绘图形。

I'm in particular interested in editing Contour properties of the surface, and the Glyph Source properties of the vectors (Shaft radius, Tip radius, Tip length). 我特别感兴趣的是编辑曲面的轮廓属性,以及矢量的字形源属性(轴半径,尖半径,尖端长度)。

Question: Is there an easy way to save the Mayavi pipeline settings until next time, or edit them directly in my Python script (ie without using the UI)? 问题:是否有一种简单的方法可以将Mayavi管道设置保存到下一次,或者直接在我的Python脚本中编辑它们(即不使用UI)?

Example: 例: 在此输入图像描述

Code: 码:

#!/usr/bin/env python
import numpy as np
from mayavi import mlab

xmax = 2.0*np.pi
x, y, z = np.mgrid[-xmax:xmax:25j, -xmax:xmax:25j, -xmax:xmax:1j]

v_x = np.sin(x)*np.cos(y)
v_y = np.cos(x)*np.sin(y) 
v_z = np.zeros_like(z)
v_abs = np.sqrt(v_x**2 + v_y**2) # scalar field

surf = mlab.surf( x[:,:,0], y[:,:,0], v_abs[:,:,0], colormap='magma' )
obj_j = mlab.quiver3d( x[:,:,0], y[:,:,0], z[:,:,-1], v_x[:,:,0], v_y[:,:,0], v_z[:,:,0], mode='arrow')

mlab.show()

For example, to change the tip length of the arrows, 例如,要更改箭头的尖端长度,

obj = mlab.quiver3d(..., mode='arrow')
obj.glyph.glyph_source.glyph_source.tip_length = 0.9

There doesn't seem to be any complete documentation of the mayavi pipeline, but one can guess from the GUI interface about the parameters: 似乎没有关于mayavi管道的任何完整文档,但是可以从GUI界面猜测参数:

在此输入图像描述

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

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