Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pwoosam opened this issue Dec 26, 2016 · 2 comments
Closed

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

pwoosam opened this issue Dec 26, 2016 · 2 comments

Comments

@pwoosam
Copy link

pwoosam commented Dec 26, 2016

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!! 🎊 🎁 🎊 ☃️

@WeatherGod
Copy link
Member

WeatherGod commented Dec 26, 2016 via email

@tacaswell
Copy link
Member

I think this should be close as a 'can not fix 😞 '.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants