Mayavi重叠时流线和图像平面对齐问题
我有一些三维的标量和向量数据,我把它们一起用流线(mlab.pipeline.streamline
)和图像平面(mlab.pipeline.image_plane_widget
)来绘图。通常这个方法是有效的,但偶尔(也就是在某些数据集上)这两种图形会出现错位的情况——尽管数据的形状完全一样。
好的例子:
坏的例子:
这种情况总是这样:流线的边界框在某个轴上被拉伸……而且没有任何设置发生变化!
举个例子,我有一个标量场 scal
,它的尺寸和一个向量场 vect
是一样的:
mlab.options.offscreen = True
# Initialized figure
fig = mlab.figure(size=[1000,1000])
extent = [0,1,0,1,0,1]
shape = np.shape(scal)
x,y,z = np.mgrid[ 0:1.0:1j*shape[0] , 0:1.0:1j*shape[1] , 0:1.0:1j*shape[2] ]
# Draw vector field
u,v,w = vect[...,0], vect[...,1], vect[...,2]
vect_field = mlab.pipeline.vector_field(x,y,z, u,v,w)
streams = mlab.pipeline.streamline(vect_field, figure=fig, extent=extent, reset_zoom=False, \
seedtype='plane', seed_scale=2.0, colormap='Greens')
streams.stream_tracer.integration_direction = 'both'
mlab.outline()
seed = streams.seed.widget
seed.set( normal=[0.0,0.0,1.0] )
seed.set( center=[0.5,0.5,0.5] )
seed.set( resolution=SEED_RESOLUTION )
seed.enabled = False
# Draw scalar field
scal = np.log10(scal)
scal_field = mlab.pipeline.scalar_field(x,y,z, scal)
midz = np.int(np.floor(shape[2]*0.5))
plane1 = mlab.pipeline.image_plane_widget(scal_field, figure=fig, plane_orientation='z_axes', \
slice_index=midz, opacity=0.1, transparent=True, \
extent=extent, reset_zoom=False )
plane2 = mlab.pipeline.image_plane_widget(scal_field, figure=fig, plane_orientation='x_axes', \
slice_index=0, opacity=0.1, \
extent=extent, reset_zoom=False )
mlab.text3d(0.5,0.5,1.07, 'Time = %04.0f' % time, scale=0.05, figure=fig)
mlab.colorbar()
mlab.view(35, 75, 3.0, focalpoint=[0.5,0.5,0.4])
可以在这里找到重现这个问题的代码和数据:
https://drive.google.com/folderview?id=0B4FXIXq2e3y4UGMyREFaWnV2Mjg&usp=sharing
1 个回答
0
问题在于 image_plane_widget
根本不接受 'extent' 这个参数。把 image_plane_widget
和 streamline
中的 'extent' 参数都去掉后,这两个对象就能对上了。