简体   繁体   中英

How do I add a scale bar to a plot in Mayavi2/VTK?

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.

Try the following:

mlab.axes()

mlab.outline()
mlab.colorbar()

This reference: http://github.enthought.com/mayavi/mayavi/auto/mlab_reference.html would help as would the several examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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