2014-01-17 65 views
2

我猜这个解决方案很简单。不过,我找不到任何有关如何更改mayavi渲染器窗口大小的示例。调整mayavi窗口

示例代码:

import numpy as np 
from tvtk.api import tvtk 
from mayavi import mlab 

points = np.random.normal(0, 1, (1000, 3)) 
ug = tvtk.UnstructuredGrid(points=points) 
ug.point_data.scalars = np.sqrt(np.sum(points**2, axis=1)) 
ug.point_data.scalars.name = "value" 
ds = mlab.pipeline.add_dataset(ug) 
delaunay = mlab.pipeline.delaunay3d(ds) 
iso = mlab.pipeline.iso_surface(delaunay) 
iso.actor.property.opacity = 0.1 
iso.contour.number_of_contours = 10 
mlab.show() 

我已经试过如下:

scene=mlab.gcf().scene 
scene.set_size((600,600)) 

没有什么变化。

最诚挚的问候和感谢提前...

回答

3
fig = mlab.figure(size=(600,600)) 
#then the rest of your code 
+2

该问题询问如何更改现有渲染器的大小。为此,这种方法不起作用,至少在我的情况下。 –

0

由于Mayavi的使用x3dom其可能通过修改DOM树的JavaScript渲染图。我在jupyter笔记本中写了这个js-cell,但我相信它可以在jupyter提供的custom.js文件中工作。 说实话,不确定性能,因为js本身对我来说是非常新的。

%%javascript 

MutationObserver = window.MutationObserver || window.WebKitMutationObserver; 
var width = 600; 
var height = 600; 

var observer = new MutationObserver(function(mutations, observer) { 
    mutations.forEach(function(mutation){ 
     if (mutation.target.className === 'x3dom-canvas') 
     { 
      var target = mutation.target; 
      if (target.getAttribute('width') < width) 
       target.setAttribute('width', width); 

      if (target.getAttribute('height') < height) 
       target.setAttribute('height', height); 
     } 
    }); 
}); 

observer.observe(document.body, { 
    subtree: true, 
    attributes: true 
}); 

代码正在观察的DOM树的修改(属性是明确的),并改变其通过Mayavi的创建特定节点的属性。