我正在尝试生成一个球体的图,一些点绘制在球体的表面上。(具体地说,这些点是Lebedev求积点)我希望我的图看起来类似于我在网上找到的图:
我首先绘制一个球面,然后用散点图覆盖它。然而,这导致我的大部分观点被底层领域“吸收”,使得它们很难被看到。看一看:
如何防止我的点被球体遮挡?下面是我用来生成这个图的脚本:
import matplotlib.pyplot as plt
from matplotlib import cm, colors
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Create a sphere
r = 1
pi = np.pi
cos = np.cos
sin = np.sin
phi, theta = np.mgrid[0.0:pi:100j, 0.0:2.0*pi:100j]
x = r*sin(phi)*cos(theta)
y = r*sin(phi)*sin(theta)
z = r*cos(phi)
#Import data
data = np.genfromtxt('leb.txt')
xx, yy, zz = np.hsplit(data, 3)
#Set colours and render
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(
x, y, z, rstride=1, cstride=1, color='c', alpha=0.6, linewidth=0)
ax.scatter(xx,yy,zz,color="k",s=20)
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_zlim([-1,1])
ax.set_aspect("equal")
plt.tight_layout()
#plt.show()
编辑
我已经找到了一种使用Python的mayavi来实现这一点的方法。下面是我得到的结果:
下面是我使用的代码:
from mayavi import mlab
import numpy as np
# Create a sphere
r = 1.0
pi = np.pi
cos = np.cos
sin = np.sin
phi, theta = np.mgrid[0:pi:101j, 0:2 * pi:101j]
x = r*sin(phi)*cos(theta)
y = r*sin(phi)*sin(theta)
z = r*cos(phi)
mlab.figure(1, bgcolor=(1, 1, 1), fgcolor=(0, 0, 0), size=(400, 300))
mlab.clf()
data = np.genfromtxt('leb.txt')
xx, yy, zz = np.hsplit(data, 3)
mlab.mesh(x , y , z, color=(0.0,0.5,0.5))
mlab.points3d(xx, yy, zz, scale_factor=0.05)
mlab.show()
发布于 2015-08-03 03:49:19
如果您认为这些点显示得不够好,可以降低球体的alpha。但是,我认为您可能将数据处理为x,y,z坐标不正确。我从这里得到了一个点的列表:http://people.sc.fsu.edu/~jburkardt/m_src/sphere_lebedev_rule_display/sphere_lebedev_rule_display.html,我的球体中的点看起来有点像你的,直到我意识到文件中包含了theta和phi的值,并且我需要将度数转换为弧度。
下面是我使用的代码:
import matplotlib.pyplot as plt
from matplotlib import cm, colors
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Create a sphere
r = 1
pi = np.pi
cos = np.cos
sin = np.sin
phi, theta = np.mgrid[0.0:pi:100j, 0.0:2.0*pi:100j]
x = r*sin(phi)*cos(theta)
y = r*sin(phi)*sin(theta)
z = r*cos(phi)
#Import data
data = np.genfromtxt('leb.txt')
theta, phi, r = np.hsplit(data, 3)
theta = theta * pi / 180.0
phi = phi * pi / 180.0
xx = sin(phi)*cos(theta)
yy = sin(phi)*sin(theta)
zz = cos(phi)
#Set colours and render
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(
x, y, z, rstride=1, cstride=1, color='c', alpha=0.3, linewidth=0)
ax.scatter(xx,yy,zz,color="k",s=20)
ax.set_xlim([-1,1])
ax.set_ylim([-1,1])
ax.set_zlim([-1,1])
ax.set_aspect("equal")
plt.tight_layout()
plt.show()
发布于 2018-10-16 21:37:42
尝试使用zorder参数。在下面给出的示例中,3D线状图将显示在3D trisurf图的顶部。为什么zorder从0到10而不是从0到1的原因是here。
plt_axes.plot_trisurf(x, y, z, shade=False, color='blue', cmap='Blues', zorder=0)
plt_axes.plot(x, y, z, marker='.', linestyle='None', label='Label', color='red', zorder=10)
https://stackoverflow.com/questions/31768031
复制相似问题