【发布时间】:2017-10-26 02:36:03
【问题描述】:
为什么 Mayavi 不能与 Jupyter 笔记本中的 ipywidgets 一起工作?我可以使用“mlab.init_notebook()”在笔记本内显示 x3d Mayavi 图像,如下所示:
from mayavi import mlab
import numpy as np
mlab.init_notebook()
mlab.clf()
phi, theta = np.mgrid[0:np.pi:11j, 0:2*np.pi:11j]
x = np.sin(phi) * np.cos(theta)
y = np.sin(phi) * np.sin(theta)
z = np.cos(phi)
mlab.mesh(x, y, z)
mlab.mesh(x, y, z, representation='wireframe', color=(0, 0, 0))
但是,如果我添加一个按钮 (ipywidget) 来回调一个函数来绘制相同的 Mayavi 图,则该图不会显示在任何地方。
from ipywidgets import widgets
from IPython.display import display
from mayavi import mlab
import numpy as np
mlab.init_notebook()
def click(a):
mlab.clf()
phi, theta = np.mgrid[0:np.pi:11j, 0:2*np.pi:11j]
x = np.sin(phi) * np.cos(theta)
y = np.sin(phi) * np.sin(theta)
z = np.cos(phi)
mlab.mesh(x, y, z)
mlab.mesh(x, y, z, representation='wireframe', color=(0, 0, 0))
button=widgets.Button(description='Click Me')
button.on_click(click)
display(button)
【问题讨论】:
标签: python-2.7 button mayavi ipywidgets