Mayavi Lock Camera

I am trying to make an animation with a sequence of data files in Mayavi. Unfortunately, I noticed that the camera does not block (it is scaled and scaled). I think this is because the Z-component of my grid is changing, and the Mayavi is trying to recalculate the scales.

How can i fix this? enter image description hereenter image description hereenter image description here

import numpy from mayavi import mlab mlab.figure(size = (1024,768),bgcolor = (1,1,1)) mlab.view(azimuth=45, elevation=60, distance=0.01, focalpoint=(0,0,0)) #mlab.move(forward=23, right=32, up=12) for i in range(8240,8243): n=numpy.arange(10,400,20) k=numpy.arange(10,400,20) [x,y] = numpy.meshgrid(k,n) z=numpy.zeros((20,20)) z[:] = 5 M = numpy.loadtxt('B:\\Dropbox\\Master.Diploma\\presentation\\movie\\1disk_j9.5xyz\\'+'{0:05}'.format(i)+'.txt') Mx = M[:,0]; My = M[:,1]; Mz = M[:,2] Mx = Mx.reshape(20,20); My = My.reshape(20,20); Mz = Mz.reshape(20,20); s = mlab.quiver3d(x,y,z,Mx, My, -Mz, mode="cone",resolution=40,scale_factor=0.016,color = (0.8,0.8,0.01)) Mz = numpy.loadtxt('B:\\Dropbox\\Master.Diploma\\presentation\\movie\\Mzi\\' + '{0:05}'.format(i) + '.txt') n=numpy.arange(2.5,400,2) k=numpy.arange(2.5,400,2) [x,y] = numpy.meshgrid(k,n) f = mlab.mesh(x, y, -Mz/1.5,representation = 'wireframe',opacity=0.3,line_width=1) mlab.savefig('B:\\Dropbox\\Master.Diploma\\presentation\\movie\\figs\\'+'{0:05}'.format(i)+'.png') mlab.clf() #mlab.savefig('B:\\Dropbox\\Master.Diploma\\figures\\vortex.png') print(i) mlab.show() 
+7
source share
3 answers

for those who are still interested in this, you can try to wrap any work that you do in this context that will turn off the rendering and return the disable_render and camera values ​​to their original states after the context is completed.

 with constant_camera_view(): do_stuff() 

Here's the class:

 class constant_camera_view(object): def __init__(self): pass def __enter__(self): self.orig_no_render = mlab.gcf().scene.disable_render if not self.orig_no_render: mlab.gcf().scene.disable_render = True cc = mlab.gcf().scene.camera self.orig_pos = cc.position self.orig_fp = cc.focal_point self.orig_view_angle = cc.view_angle self.orig_view_up = cc.view_up self.orig_clipping_range = cc.clipping_range def __exit__(self, t, val, trace): cc = mlab.gcf().scene.camera cc.position = self.orig_pos cc.focal_point = self.orig_fp cc.view_angle = self.orig_view_angle cc.view_up = self.orig_view_up cc.clipping_range = self.orig_clipping_range if not self.orig_no_render: mlab.gcf().scene.disable_render = False if t != None: print t, val, trace ipdb.post_mortem(trace) 
+4
source

I really don't see a problem in your plot, but resetting the view after each instance of the graph inserts your viewpoint:

 mlab.view(azimuth=45, elevation=60, distance=0.01, focalpoint=(0,0,0)) 

directly above your mlab.savefig call in your for loop.

+1
source

You can simply use the vmin and vmax functions in your mesh command, if you do this, the scale will not change with your data, and your camera should stay where it is. Like this:

 f = mlab.mesh(x, y, -Mz/1.5,representation = 'wireframe',vmin='''some value''',vmax='''some value''',opacity=0.3,line_width=1) 
+1
source

All Articles