Python Mayavi曲面图:绘制轴时出错

时间:2016-10-21 23:13:36

标签: python python-2.7 matplotlib mayavi mayavi.mlab

我在python2.7上使用Mayavi来绘制3d表面。尝试将轴添加到调用函数mlab.axes()的3D绘图时会出现问题。

以下是我的代码片段:

from mayavi import mlab
mlab.figure(bgcolor=(1, 1, 1))
s = mlab.surf(x, y, z_func, extent=(0,1, 0,1, 0,1))
mlab.outline(s, extent=(0,1, 0,1, 0,1))
ax = mlab.axes(s, extent=(0,1, 0,1, 0,1))

使用此代码,我可以查看曲面图并与其进行交互,但代码会引发与函数axes()相关的异常。

这是我在运行脚本时遇到的错误:

No handlers could be found for logger "mayavi.core.common"
Exception occurred in traits notification handler.
Please check the log file for details.
Exception occurred in traits notification handler for object: <mayavi.tools.decorations.Axes object at 0x7f521d6a3230>, trait: extent, old value: [0 0 0 0 0 0], new value: [0 1 0 1 0 1]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/traits/trait_notifiers.py", line 340, in __call__
    self.handler( *args )
  File "/usr/local/lib/python2.7/dist-packages/mayavi/tools/decorations.py", line 373, in _extent_changed
    axes.module_manager.source.outputs[0].bounds
AttributeError: 'PolyDataNormals' object has no attribute 'bounds'
Traceback (most recent call last):
  File "teste3.py", line 47, in <module>
    test_surf()
  File "teste3.py", line 36, in test_surf
    ax = mlab.axes(s2, extent=(0,1, 0,1, 0,1))
  File "/usr/local/lib/python2.7/dist-packages/mayavi/tools/pipe_base.py", line 38, in the_function
    factory = factory_class(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mayavi/tools/decorations.py", line 309, in __init__
    SingletonModuleFactory.__init__(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mayavi/tools/decorations.py", line 264, in __init__
    self.set(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/mayavi/tools/pipe_base.py", line 179, in set
    callback()
  File "/usr/local/lib/python2.7/dist-packages/mayavi/tools/decorations.py", line 373, in _extent_changed
    axes.module_manager.source.outputs[0].bounds
AttributeError: 'PolyDataNormals' object has no attribute 'bounds'

此外,还会显示以下窗口报告异常: Mayavi/vtk surface plot axes() error

有谁知道如何解决这个问题?

0 个答案:

没有答案