-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Labels
Comments
This this is a known limitation of mplot3d. It is not a true 3d rendering
toolkit, and it is constrained by the layering engine of matplotlib. Each
artist gets a single zorder value, which determines the order in which
artists and collections are drawn. As such, the rendering of mixed 3d
scenes is impossible in the general case because either the surface artist
or the scatter artist has to be drawn before the other.
You might want to look at glumpy, which is an open GL project that borrows
heavily from matplotlib. It does true 3d rendering, and may be more
suitable for your needs.
…On Dec 26, 2016 12:44 AM, "Patrick Woo-Sam" ***@***.***> wrote:
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.
[image: angle1]
<https://cloud.githubusercontent.com/assets/18713517/21476043/644b5618-cae8-11e6-8692-adc2b9f9cc8a.png>
[image: angle2]
<https://cloud.githubusercontent.com/assets/18713517/21476044/6ab4a0d6-cae8-11e6-8a9d-cfdc12ed374b.png>
[image: angle3]
<https://cloud.githubusercontent.com/assets/18713517/21476045/6f7b018c-cae8-11e6-9a7a-0c8f09fb48c7.png>
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)
[image: figure_11]
<https://cloud.githubusercontent.com/assets/18713517/21476191/8dbba03c-caea-11e6-89d7-78ec2cdbb96b.png>
[image: figure_12]
<https://cloud.githubusercontent.com/assets/18713517/21476196/93948d8e-caea-11e6-9192-29dda8e7c6ea.png>
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#7684>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AARy-NcRhyopCtgr_cLPioOiK1u7K9jOks5rL1RPgaJpZM4LVkel>
.
|
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
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.
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!! 🎊 🎁 🎊 ☃️
The text was updated successfully, but these errors were encountered: