2

I have two Matplotlib plot_surfaces that intersect. For example, two spheres that are close enough to intersect.

When I use the mouse to move the camera angle, I expect proper occlusion (I.e. not to see the parts of the sphere that are hidden by the occlusion).

Instead I am stuck seeing one object always fully rendered on top of the other.

I need to render png files for an important presentation. But with the current occlusion being so wrong... I can't use any screenshots.

How do you get proper occlusion of surfaces?

Does non interactive backends and renderers do occlusion correctly? (If yes, then that would be a way-forward. Albeit a non-ideal and inelegant way-forward... but at least I can save pictures of the figure that would be usable in my presentation by programmatically setting the camera's elevation and azimuth and camer center.)


Minimal, Complete, and Verifiable example code:

#!/usr/bin/python2
# from: http://matplotlib.org/mpl_examples/mplot3d/surface3d_demo2.py
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)

x = 1 * np.outer(np.cos(u), np.sin(v))
y = 1 * np.outer(np.sin(u), np.sin(v))
z = 1 * np.outer(np.ones(np.size(u)), np.cos(v))
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')
# modification from original code
ax.plot_surface(x+1.5, y, z, rstride=4, cstride=4, color='b')

plt.show()

screenshots:

enter image description here

enter image description here

for some reason when you rotate the camera's azimuth this causes one object to be painted on top of the other. these two screen shots demonstrate azimuth -88 degrees and then -92 degrees. so maybe the issue is the -90 degrees. OR maybe whatever plot_surface object that has a center that is closer to the camera gets rendered on top of the other object.

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177
  • You may use transparency (alpha < 1)? this does not solve the problem but at least the illusion of intersection between the surfaces looks better. – user2660966 Oct 27 '16 at 07:36

0 Answers0