具有多个半径的单线与 Mayavi [英] Single line with multiple radii with Mayavi

查看:24
本文介绍了具有多个半径的单线与 Mayavi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Mayavi 中绘制一条宽度或半径不恒定的线(或管).这似乎是一项简单的任务,尽管我可能不太了解幕后发生的事情,无法实现这一点.

I am trying to plot a single line (or tube) in Mayavi that has a non-constant width or radius. This seems like a simple task though I may not be understanding what is happening behind the scenes well enough to make this happen.

以下代码创建了我想要的线条,并且我可以按颜色缩放;但是,我也想按宽度缩放.

The following code creates the line I want, and I am able to scale by color; however, I would also like to scale by width.

import mayavi.mlab as mlab
import numpy as np

x = range(100)
y = range(100)
z = range(100)
s = np.random.uniform(0, 1, 100)

mlab.plot3d(x, y, z, s, tube_radius=10)

我没有所需输出的图像,因为我无法创建它,尽管它本质上是按半径而不是颜色缩放的前一个图像,因此线条的某些区域会比其他区域更宽.一种可能的解决方案是使用 tube_radius 参数并单独绘制每个部分,尽管这看起来确实很糟糕,因为线条可能会很长并且有许多不同的部分.

I don't have an image of the desired output as I am unable to create it, though it would essentially be the preceding image scaled by radius instead of color, so that some areas of the line would be wider than other areas. One possible solution would be to use the tube_radius parameter and plot each section individually, though this really seems like poor practice as the lines can get quite long and have many different sections.

推荐答案

在 GUI 中,您可以转到 Tube 管道并使用 Vary_radius = 'vary_radius_by_scalar'

In the GUI, you can go to the Tube pipeline and use Vary_radius = 'vary_radius_by_scalar'

在脚本中你可以做

import mayavi.mlab as mlab
import numpy as np

x = range(100)
y = range(100)
z = range(100)
s = np.random.uniform(0, 1, 100)

t = mlab.plot3d(x, y, z, s, tube_radius=10)
t.parent.parent.filter.vary_radius = 'vary_radius_by_scalar'

因为表面的父级是模块管理器(颜色等),而它的父级是 Tube 管道

Since the parent of the surface is the Module manager (colors, etc) and its parent is the Tube pipeline

这篇关于具有多个半径的单线与 Mayavi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆