Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

python - Matplotlib 3D plot zorder issue

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: enter image description here

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:

enter image description here

Until the red sphere completely disappears: enter image description here

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

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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...