Ho alcuni dati che consistono in diverse immagini 2D che vorrei rappresentare in specifiche [x, y, z] posizioni l'una rispetto all'altra usando mayavi2 (v4.3.0)
.mayavi - impostazione programmata dell'estensione [x, y, z] di un'immagine
From the documentation sembra che dovrei essere in grado di farlo con mlab.imshow()
. Sfortunatamente, mayavi lancia un'eccezione quando chiamo imshow
specificando il parametro extent
(AttributeError: 'ImageActor' object has no attribute 'actor'
).
Ho anche provato a impostare i dati x, ye direttamente modificando im.mlab_source.x,y,z...
. Stranamente, sebbene questo modifichi correttamente le estensioni x e y, non fa nulla per la posizione z anche se im.mlab_source.z
cambia chiaramente.
Ecco un esempio eseguibile:
import numpy as np
from scipy.misc import lena
from mayavi import mlab
def normal_imshow(img=lena()):
return mlab.imshow(img,colormap='gray')
def set_extent(img=lena()):
return mlab.imshow(img,extent=[0,100,0,100,50,50],colormap='cool')
def set_xyz(img=lena()):
im = mlab.imshow(img,colormap='hot')
src = im.mlab_source
print 'Old z :',src.z
src.x = 100*(src.x - src.x.min())/(src.x.max() - src.x.min())
src.y = 100*(src.y - src.y.min())/(src.x.max() - src.y.min())
src.z[:] = 50
print 'New z :',src.z
return im
if __name__ == '__main__':
# this works
normal_imshow()
# # this fails (AttributeError)
# set_extent()
# weirdly, this seems to work for the x and y axes, but does not change
# the z-postion even though data.z does change
set_xyz()