Skip to content

3-D scatter plot disappears when overlaid over a 3-D surface plot. #7684

@pwoosam

Description

@pwoosam

I am trying to generate a 3-D surface plot with a 3-D scatter plot overlaid.
The issue is that not all of the points are visible when they are on the surface of the surface plot.

angle1
angle2
angle3

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()
ax = fig.gca(projection='3d')

x = np.arange(200)
y = np.arange(200)
x, y = np.meshgrid(x, y)
z = np.zeros((200, 200))

# Create index arrays.
I, J = np.meshgrid(np.arange(200), np.arange(200))

# Calculate distance of all points to center.
dist = np.sqrt((I - 100)**2 + (J - 100)**2)

# Create the peak.
radius = 50
height = 1
curve = np.linspace(0, np.pi, radius*2)
z_peak = [(np.cos(i) + 1) * height / 2 for i in curve]
for cr, h in enumerate(z_peak):
    z = np.where(dist < cr, z, h)

ax.plot_surface(x, y, z, rstride=1, cstride=1, linewidths=0, cmap='terrain')

# Generate points to represent population.
x_ = np.random.randint(0, 200, size=100)
y_ = np.random.randint(0, 200, size=100)
z_ = []
for x, y in zip(x_, y_):
    z_.append(z[x, y])
points = ax.scatter(x_, y_, z_)

Another issue is that at some angles, points on the other side of the surface plot's peak are visible. They should not be visible through the surface unless the surface plot's alpha is set below 1.

To see this, change:
z_.append(z[x, y])
to
z_.append(z[x, y] + 0.2)

figure_11
figure_12
Note: I also changed the stride values for the surface plot to their default values. It has little effect on the issue though.

System Info:
Matplotlib: 1.5.3 (from Anaconda installer)
Python: 3.5.2 (from Anaconda installer)
Platform: Windows 10

P.S. Happy Holidays!! 🎊 🎁 🎊 ☃️

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions