如何在 Mayavi2/VTK 中向绘图添加比例尺?
我想在我用 mlab 创建的 mayavi 图中添加一个比例尺(例如显示微米有多大)。
例如,引用这个问题:如何要在 mayavi 中正确显示具有非立方体素的体积,
我可以通过使用设置绘图的体素大小,
from enthought.mayavi import mlab
import numpy as np
s=64
x,y,z = np.ogrid[0:s,0:s,0:s/2]
volume = np.sqrt((x-s/2)**2 + (y-s/2)**2 + (2*z-s/2)**2)
grid = mlab.pipeline.scalar_field(data)
grid.spacing = [1.0, 1.0, 2.0]
contours = mlab.pipeline.contour_surface(grid,
contours=[5,15,25], transparent=True)
mlab.show()
我想要一种自动方式添加一些指示我所显示的对象的比例的指标。现在我正在使用 inkscape 手动添加比例尺到导出的图像,但必须有更好的方法。
一个简单的 Mayavi 方法将是最有帮助的,但是如果 vtk 中有任何东西可以做到这一点,我总是可以使用 Mayavi 的包装器。
像 text3d 这样的东西可以让我添加文本,然后我想我也可以弄清楚如何画一条线并手动计算正确的缩放比例,但我希望有一种更简单的方法。
I would like to add a scale bar (showing how big a micron is for example) to a mayavi plot I create with mlab.
For example, referencing this question: How to display a volume with non-cubic voxels correctly in mayavi
I can set the voxel size of a plot by using
from enthought.mayavi import mlab
import numpy as np
s=64
x,y,z = np.ogrid[0:s,0:s,0:s/2]
volume = np.sqrt((x-s/2)**2 + (y-s/2)**2 + (2*z-s/2)**2)
grid = mlab.pipeline.scalar_field(data)
grid.spacing = [1.0, 1.0, 2.0]
contours = mlab.pipeline.contour_surface(grid,
contours=[5,15,25], transparent=True)
mlab.show()
I would like an automated way of adding a some indicator of what the scale of the object I am showing is. Right now I am adding scale bars by hand with inkscape to exported images, but there has to be a better way.
A straightforward mayavi way would be most helpful, but if there is anything in vtk that would do it, I can always use mayavi's wrapper.
Something like text3d will let me add text, and then I suppose I could figure out how to draw a line as well and compute the correct scaling by hand, but I am hoping there is an easier way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下操作:
此参考:http://github.enthought.com/mayavi/ mayavi/auto/mlab_reference.html 和几个示例一样会有所帮助。
Try the following:
This reference: http://github.enthought.com/mayavi/mayavi/auto/mlab_reference.html would help as would the several examples.