Python 调整mayavi窗口的大小
我想解决办法很简单。但是,我找不到任何关于如何更改mayavi渲染器窗口大小的示例 示例代码:Python 调整mayavi窗口的大小,python,window,vtk,mayavi,Python,Window,Vtk,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**
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))
没有什么变化
向您致以最诚挚的问候和感谢…因为Mayavi使用x3dom渲染绘图,所以可以使用javascript修改DOM树。我在jupyter笔记本中编写了这个js单元,但我相信它可以在jupyter提供的custom.js文件中工作。
fig = mlab.figure(size=(600,600))
#then the rest of your code
老实说,我不确定性能,因为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创建的特定节点的属性。因为Mayavi使用x3dom渲染绘图,所以可以使用javascript修改DOM树。我在jupyter笔记本中编写了这个js单元,但我相信它可以在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创建的特定节点的属性。问题询问如何更改现有渲染器的大小。为此,至少在我的例子中,这种方法不起作用。问题是如何更改现有渲染器的大小。出于这个目的,这种方法不起作用,至少在我的例子中是这样。