2015-10-01 2 views
3

Я планирую облако точек и окраску остаточной ошибкой. Я хотел бы, чтобы цветовая палитра оставалась центрированной на 0, так что ошибка 0 была белой.Центр colormap вокруг 0 ​​в Mayavi

Я вижу answers for matplotlib. А как насчет майяви?

from mayavi import mlab 
mlab.points3d(x, y, z, e, colormap='RdBu') 

ответ

1

вы можете установить vmin и vmax цветовую карту явно с mlab.points3d. Таким образом, вы можете просто убедиться, что 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

В случае кто-то хочет это сделать, но так, чтобы в полной мере степень Colorbar используется здесь это решение, которое я сделал (с помощью here) для MayaVi, который тянется Colorbar так, что центр его на ноль:

#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 несколько раз для одной и той же поверхности (т. если вы изменяете скаляры майави, а не перерисовываете сюжет), вам нужно сделать запись начальной таблицы лут и изменить это каждый раз.

Смежные вопросы