Matplotlib 3D绘图zorder问题

时间:2014-04-20 23:03:22

标签: python matplotlib

我有一个由蓝色表面(通过plot_surface绘制)和红色球体(通过scatter绘制)组成的图。曲面的zorder设置为0,并且球体的zorder设置为1(尽管未设置任何zorder值会产生相同的结果)。

您可以看到红色球体位于曲面的左侧: enter image description here

当我旋转绘图时,您可以看到红色球体开始消失在蓝色表面后面,即使它在它前面

enter image description here

直到红色球体完全消失: enter image description here

奇怪的是,对于某些角度/视图,红色球体重新出现并再次可见,例如: enter image description here

这里发生了什么?我已经阅读了其他一些与绘图/ zorder相关的问题,但我还没有看到这种行为,其中一个对象明显位于另一个对象的前方/前方,并且在大多数视角下无法正确显示。

如果我使蓝色表面透明,当它在下面的图中消失时,你可以看到表面后面的红色球体(所以看起来绘图库实际上认为它在表面之后)。

1 个答案:

答案 0 :(得分:2)

这仍然是Matplotlib 1.5.3(2016)中的一个问题。 @tacaswell(他是Matplotlib dev的联合负责人)建议使用Mayavi来处理3D绘图,这种绘图在Python绘图库中相对独特,因为它不像许多其他项目那样使用Matplotlib作为后端(Pandas, Seaborn,ggplot)。

我能够使用Homebrew和pip,在OSX上安装Mayavi,而不是大惊小怪。

#/bin/bash
# vtk is a mayavi requirement
brew install vtk
pip install mayavi
# Port your matplotlib code to mayavi
# Profit...