-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Labels
Description
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.
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)
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!! 🎊 🎁 🎊 ☃️
bfmat, Atcold, alexbertis, sunshineatnoon, taless474 and 1 more