2015-10-01 47 views

回答

1

你可以mlab.points3d設置顏色表的vminvmax明確。所以,你可以確保vmin = -vmax。事情是這樣的:

mylimit = 10 
mlab.points3d(x, y, z, e, colormap='RdBu',vmin=-mylimit,vmax=mylimit) 

或者,你可以用像自動設置的限制:

mylimit = max(abs(e.min()),abs(e.max())) 
1

如果有人想這樣做,但這樣的彩條的充分程度時,在這裏是綿延的彩條,使得它的中心是一個解決方案,我做(與here幫助)對Mayavi的零:

#Mayavi surface 
s = mlab.surf(data) 
#Get the lut table of the data 
lut = s.module_manager.scalar_lut_manager.lut.table.asarray() 

maxd = np.max(data) 
mind = np.min(data) 
#Data range 
dran = maxd - mind 

#Proportion of the data range at which the centred value lies 
zdp = abs(mind/dran)  

#The +0.5's here are because floats are rounded down when converted to ints 
#index equal portion of distance along colormap 
cmzi = int(zdp * 255 + 0.5) 
#linspace from zero to 128, with number of points matching portion to side of zero 
topi = np.linspace(0, 127, cmzi) + 0.5 
#and for other side 
boti = np.linspace(128, 255, 255 - cmzi) + 0.5  

#convert these linspaces to ints and map the new lut from these  
shift_index = np.hstack([topi.astype(int), boti.astype(int)]) 
s.module_manager.scalar_lut_manager.lut.table = self.lut[shift_index] 

#Force update of the figure now that we have changed the LUT 
mlab.draw() 

需要注意的是,如果你想做到這一點MUL相同表面的三倍時間(即,如果您正在修改mayavi標量而不是重新繪製該圖),則需要記錄最初的lut表並每次修改該表。