enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.28k stars 282 forks source link

Not possible to change light_mode in Python script #1226

Closed FinnHoller closed 1 year ago

FinnHoller commented 1 year ago

I was under the impression that Mayavi uses the "Raymond" light_mode by default, but when exporting a PNG with the 'savefig' method, the VTK lighting seems to be used.

I would like to change the light_mode inside my Python script but this seems to be impossible as the light_manager is None.

I am using following code:

import mayavi.mlab as mlab
g = mlab.test_plot3d()
print(None == g.scene.light_manager)
mlab.savefig('test.png')

Which prints 'True'. The light_manager seems to be set somewhere in the figure saving process, I am looking for a way to modify it beforehand.

prabhuramachandran commented 1 year ago

The trouble here is that the scene is not yet constructed when you print. You can use this hack (this needs a better solution):

g = mlab.test_plot3d()
g.scene._lift()
...
prabhuramachandran commented 1 year ago

If you use the version of Mayavi from github today, you can instead use mlab.process_ui_events() instead of g.scene._lift() to fix the issue.