我正在尝试用python创建一个bokeh服务器应用程序,我想在其中使用交互式窗口小部件和Mayavi 2计算和显示3D绘图。我可以使Mayavi绘图显示在独立窗口上。然而,我更希望将绘图嵌入到由bokeh应用程序创建的客户端网页内的绘图窗口中。下面是bokeh服务器应用程序的示例代码。如果单击该按钮,将创建Mayavi图。我只希望绘图窗口显示在按钮旁边的绘图窗口中,而不是单独的窗口中。这个是可能的吗?在此之前非常感谢。

from bokeh.plotting import figure
from bokeh.io import curdoc
from bokeh.layouts import row, column, widgetbox
from bokeh.embed import notebook_div
from bokeh.models.widgets import Slider, TextInput, Button, Toggle
from mayavi import mlab
import numpy as np
# Set up plot
plot = figure(x_axis_location=None, y_axis_location=None, plot_width=400, plot_height=400, title = "3D plot", logo=None)
def MayaviPlot(attrname, old, new):
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))
mlab.show()
button1 = Toggle(label="Plot", button_type="success")
button1.on_change('active', MayaviPlot)
inputs = button1
outputs = plot
curdoc().add_root(row(inputs, outputs, width=1000))
curdoc().title = "Test"
发布于 2018-06-07 15:46:33
这是不可能的。Bokeh只在浏览器内部显示。但是当你运行mlab.show时,它实际上运行了一个单独的可执行程序,而我所知道的是,没有办法将它嵌入到浏览器中。
https://stackoverflow.com/questions/46942599
复制相似问题