如何在Matplotlib中的3D绘图中使对象不透明

时间:2016-06-10 14:54:55

标签: python mplot3d

所以目前我正在绘制一颗卫星绕地球的路径。这是一个为期3个月的任务,我每15天绘制一个卫星轨道,以显示轨道如何变化。目前我有这段代码:

#######################################################################
    # 3-D Plotting (1 Orbit Done per 15 Days = 1,296,000 Seconds
                # 1,296,000 Seconds = 43,200 Data points
#######################################################################

time_step = 40320 # Data points in Fifteen Days
fig = plt.figure(figsize=(20,10))
ax = fig.add_subplot(111, projection='3d')
ax.set_aspect('equal')

u = numpy.linspace(0, 2 * numpy.pi, 100)
v = numpy.linspace(0, numpy.pi, 100)

x_sphere = 1 * numpy.outer(numpy.cos(u), numpy.sin(v))
y_sphere = 1 * numpy.outer(numpy.sin(u), numpy.sin(v))
z_sphere = 1 * numpy.outer(numpy.ones(numpy.size(u)), numpy.cos(v))

ax.plot_surface(x_sphere, y_sphere, z_sphere,  rstride=1, cstride=1, color='white', linewidth=0, alpha=1.)

ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
ax.set_zlabel('Z axis')

colors =     ['red','orange','yellow','green','blue','indigo','violet','pink','tan','teal','brown','gray','coral']

for num in range(2):
    x = numpy.transpose(x_coords_row_interp)[num*time_step:(num*time_step)+187] # One Period Every 93.47137682 Minutes (~186.943 half minutes)
    y = numpy.transpose(y_coords_row_interp)[num*time_step:(num*time_step)+187] # One Period Every 93.47137682 Minutes (~186.943 half minutes)
    z = numpy.transpose(z_coords_row_interp)[num*time_step:(num*time_step)+187] # One Period Every 93.47137682 Minutes (~186.943 half minutes)

    ax.scatter(x, y, z, s=0)
    count = 0
    for i in range(len(x)):
    while count < len(x)-1:
        ax.plot([x[count][0],x[count+1][0]],[y[count][0],y[count+1][0]],[z[count][0],z[count+1][0]],color = colors[num])
        count=count+1

    red = plt.Rectangle((0, 0), 1, 1, fc="red")
    orange = plt.Rectangle((0, 0), 1, 1, fc="orange")

    ax.legend([red,orange],['Zero Days','Fifteen Days'])

    ax.view_init(elev=20., azim=45)

产生此图片:http://i.stack.imgur.com/rXJGr.png

然而,由于球体透明度,很难破译轨道所在球体的哪一侧。如何使球体不透明,以便更容易可视化轨道的路径?

0 个答案:

没有答案