Update a mayavi plot programmatically
Opened this issue · 0 comments
Is there an easy solution to force the update of a Mayavi plot, e.g. after its source data is updated?
Using mlab.animate() as suggested in the documentation works but is not suitable for me, since the flow is not under control of the user: replotting occurs at predefined regular time intervals. I would like to be able to replot based on some conditions in my program.
Traits might be a solution, but it seems rather complicated for a simple task, and unclear how updates can be triggered programmatically rather than via user interaction in the GUI dialog window, i.e., one of the issues is to feed into the event loop started by mlab.show().
Here is how I would ideally see this feature (adapted from the example in the doc at the link above):
import numpy as np
from mayavi import mlab
x, y = np.mgrid[0:3:1,0:3:1]
s = mlab.surf(x, y, np.asarray(x*0.1, 'd'))
mlab.show() # <== issue: hangs there until mayavi window is closed to continue execution of the script.
for i in range(10):
s.mlab_source.scalars = np.asarray(x*0.1*(i+1), 'd')
s.refresh() # <== or similar