python - mayavi 无法渲染 3d 体积

标签 python jupyter-notebook mayavi

我尝试在 jupyter notebook 中使用 mayavi 渲染体积来测试下面的示例

from mayavi import mlab
mlab.init_notebook()
x, y, z = np.ogrid[-10:10:20j, -10:10:20j, -10:10:20j]
s = np.sin(x*y*z)/(x*y*z)
mlab.pipeline.volume(mlab.pipeline.scalar_field(s))

我收到错误:

Notebook initialized with x3d backend.
--------------------------------------------------------------------------- AttributeError                            Traceback (most recent call last) /Users/phan/anaconda/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    309             method = get_real_method(obj, self.print_method)
    310             if method is not None:
--> 311                 return method()
    312             return None
    313         else:

/Users/phan/anaconda/lib/python2.7/site-packages/mayavi/tools/notebook.pyc in _repr_html_(self)
     58         return scene_to_png(scene)
     59     elif _backend == 'x3d':
---> 60         return scene_to_x3d(scene)
     61 
     62 

/Users/phan/anaconda/lib/python2.7/site-packages/mayavi/tools/notebook.pyc in scene_to_x3d(scene)
     91     else:
     92         url_base = "http://www.x3dom.org/download"
---> 93     x3d_elem = _fix_x3d_header(ex.output_string)
     94     html = '''
     95     %s

/Users/phan/anaconda/lib/python2.7/site-packages/mayavi/tools/notebook.pyc in _fix_x3d_header(x3d)
     70     rep += '>'
     71 
---> 72     x3d = x3d.replace(
     73         '<X3D profile="Immersive" version="3.0">',
     74         rep

AttributeError: 'NoneType' object has no attribute 'replace'

Out[39]: <mayavi.modules.volume.Volume at 0x132e605f0>

我在 anaconda 中安装了 Python 2.7、VTK 6.3、trait 4.6。

最佳答案

你安装了x3d了吗?安装扩展,mayavi doc给出的方法是

jupyter nbextension install --py mayavi --user

(参见 http://docs.enthought.com/mayavi/mayavi/tips.html#using-mayavi-in-jupyter-notebooks)。

这应该可以解决问题。

关于python - mayavi 无法渲染 3d 体积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40764116/

相关文章:

python - 使用 Python 将颜色图/渐变图应用于图像

python - Mayavi:自定义工具栏

python - 在 virtualenv : installed sklearn module not available 中运行 Jupyter notebook

python - 如何以编程方式查找 Mayavi 颜色图的有效名称?

python - 值错误 : cannot set toolkit to wx because it has already been set to qt4

python - 尝试替换 pandas 数据框中的停用词,发生 sre_constants.error

python - 如何将具有无效 UTF-8 字符的文件名转换回字节?

python - 向量化数组操作的源码位置和解释

python - 在 VS code python notebook 中将 autopep8 和 linting 添加到 jupyter

python - 如何以交互方式将一个代码的输出输入到另一个代码中并从 Pycharm 交互式 python 控制台运行它们?