简体   繁体   中英

Mayavi view current camera settings

I would like to be able to set the view of my mayavi plot to a view that I have set in the interactive window. The view can be set with the mlab.view interface. However, I can't seem to find the view parameters from within the mayavi interactive GUI.

When viewing a plot in interactive mode in matplotlib , the camera angle and azimuth are displayed in the bottom of the screen as seen here:

在此处输入图像描述

This is convenient, because to replicate a view I like, I can just read off the elevation and azimuth and set them in my code (in this case with ax.view_init(elev=-9, azim=84) . I would like to do the same in mayavi . Given this code example:

from mayavi import mlab
import numpy as np
    
img = np.random.uniform(0, 255, size=(512, 512)).astype(np.int)

N = 10000
event_size = 2
xs = np.random.uniform(img.shape[1], size=N)
ys = np.random.uniform(img.shape[0], size=N)
ts = np.sort(np.random.uniform(1000, size=N))
ps = np.random.randint(0,2,size=N)

mlab.imshow(img, colormap='gray', extent=[0, img.shape[0], 0, img.shape[1], ts[0], ts[1]])
colors = [0 if p>0 else 240 for p in ps]
ones = np.ones(len(xs))
p3d = mlab.quiver3d(ys, xs, ts, ones, ones,
            ones, scalars=colors, mode='sphere', scale_factor=event_size)
p3d.glyph.color_mode = 'color_by_scalar'

p3d.module_manager.scalar_lut_manager.lut.table = colors
mlab.draw()
mlab.show()

This code should create an image and a point cloud and display it in an interactive window. Where in the window can I tell what the current camera parameters are and how would I apply them in the code? Many thanks!

One solution I found in the documentation was to use the mayavi record feature in the UI. This will log all actions to a python executable script, which will print the camera positions you place the scene in.

Alternatively, when in the mayavi UI, one can type python commands in the UI terminal, so entering

from mayavi import mlab
print(mlab.view())

will also give the camera params.

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