Matplotlib 3D图zorder问题 [英] Matplotlib 3D plot zorder issue

查看:359
本文介绍了Matplotlib 3D图zorder问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a plot consisting of a blue surface (plotted via plot_surface) and a red sphere (plotted via scatter). The zorder of the surface is set to 0, and the zorder of the sphere is set to 1 (though not setting any zorder values yields the same results).

您会看到红色球体位于表面的左侧:

You can see that the red sphere is to the left of the surface:

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

As I rotate the plot you can see the red sphere start to disappear behind the blue surface even though it's in front of it:

直到红色球体完全消失:

Until the red sphere completely disappears:

奇怪的是,对于某些角度/视图,红色球再次出现并再次可见,例如:

What is strange is that for certain angles/views the red sphere re-appears and is visible again, such as this one:

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

What's going on here? I've read some of the other plotting/zorder related issues but I haven't seen this type of behavior where one object is clearly behind/in-front of another and it isn't displayed correctly for most viewing angles.

如果我使蓝色表面透明,则当下面的图中的红色球消失时,您会看到表面后面的红色球体(因此,似乎绘图库实际上认为它位于表面的后面).

If I make the blue surface transparent, you can see the red sphere behind the surface when it disappears in the plots below (so it seems like the plotting library actually thinks that it's behind the surface).

推荐答案

在Matplotlib 1.5.3(2016)中,这仍然是一个问题. @tacaswell(是Matplotlib开发的共同负责人)推荐的另一种选择是使用Mayavi处理3D绘图,这在Python绘图库中是相对独特的,因为它不像许多其他项目那样将Matplotlib作为后端使用(熊猫, Seaborn,ggplot).

This is still an issue in Matplotlib 1.5.3 (2016). The alternative that @tacaswell (who is a co-lead on Matplotlib dev) recommends is to handle 3D plotting using Mayavi which is relatively unique amongst Python plotting libraries in that it does not use Matplotlib as a backend like many other projects do (Pandas, Seaborn, ggplot).

我能够使用 Homebrew 和pip在OSX上进行最小程度的麻烦安装.

I was able to install Mayavi on OSX with a minimum of fuss using Homebrew and pip.

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

这篇关于Matplotlib 3D图zorder问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆