[英]Resize mayavi window
I guess the solution is quite easy. 我想解决方案很容易。 However I can't find any example on how to change the window size of the mayavi renderer.
但是我找不到任何有关如何更改mayavi渲染器的窗口大小的示例。
sample code: 样例代码:
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()
I've tried the following: 我尝试了以下方法:
scene=mlab.gcf().scene
scene.set_size((600,600))
nothing changes. 没有什么变化。
best regards and thanks in advance... 最好的问候和预先的感谢...
fig = mlab.figure(size=(600,600))
#then the rest of your code
Since Mayavi render plots using x3dom its possible by modifying DOM tree with javascript. 由于Mayavi使用x3dom渲染图,因此可以通过使用javascript修改DOM树来实现。 I wrote this js-cell in my jupyter notebook but i believe it will work inside custom.js file jupyter provides.
我在jupyter笔记本中编写了这个js单元,但我相信它将在jupyter提供的custom.js文件中运行。 To be honest not sure about performance because js itself is pretty new for me.
老实说,不确定性能,因为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
});
Code is observing DOM tree modifications (attributes to be clear) and changing specific node's attributes which created by Mayavi. 代码正在观察DOM树修改(属性要清楚)并更改Mayavi创建的特定节点的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.