通过scatter3d显示的球面上的点仅显示为平面/圆盘,而不显示为球

时间:2019-03-05 13:25:59

标签: python plotly

当前,我正在尝试显示分布在球体一半上的点,并使用scatter3d对其进行绘图显示。当我使用matplotlib进行此操作时,它可以很好地工作。这是一张图像,在matplotlib中是什么样子,在plotly中也应该是什么样子(注意:忽略颜色,只有点的位置很重要):

matplot sphere

现在,如果我在情节上这样做,看起来像这样: plotly sphere

以下是相关代码:

def view_sensor_grid_result(sensor):
    ## matplot ##
    matplot_x_hit = []  # needed for color
    matplot_y_hit = []
    matplot_z_hit = []
    matplot_x_miss = []  # needed for color
    matplot_y_miss = []
    matplot_z_miss = []

    for angle in sensor.angle_hits:
        if angle.hit == 1:
            matplot_x_hit.append(angle.coord_x)
            matplot_y_hit.append(angle.coord_y)
            matplot_z_hit.append(angle.coord_z)
        else:
            matplot_x_miss.append(angle.coord_x)
            matplot_y_miss.append(angle.coord_y)
            matplot_z_miss.append(angle.coord_z)

    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(matplot_x_hit, matplot_y_hit, matplot_z_hit, c='r', marker='o')  # all hits are red
    ax.scatter(matplot_x_miss, matplot_y_miss, matplot_z_miss, c='b', marker='o')  # all misses are blue
    ax.scatter([sensor.utm_x], [sensor.utm_y], [sensor.utm_z], c='g', marker='o')
    plt.show()


    ## plotly  ##
    angle_traces = []
    for angle in sensor.angle_hits:
        hit_x = [angle.coord_x]
        hit_y = [angle.coord_y]
        hit_z = [angle.coord_z]

        s_color = default_sensor_color_hit
        if angle.hit == 1:  # needed for color
            s_color = default_sensor_color_miss
        angle_trace = go.Scatter3d(
            x=hit_x,
            y=hit_y,
            z=hit_z,
            mode='markers',
            marker=dict(
                size=3,
                line=dict(
                    color='#000000',
                    width=0.0
                ),
                color=s_color,
                opacity=1.0
            )
        )
        angle_traces.append(angle_trace)

    layout = go.Layout(title="Grid for sensor {}".format(sensor.id), xaxis={'title': 'x - easting(?)'}, yaxis={'title': 'y - northing(?)'})
    fig = go.Figure(data=angle_traces, layout=layout)
    fig['layout']['scene'].update(go.layout.Scene(aspectmode='data'))
    off_plot(fig, filename='./results/plots/sensor_grids/sensor_{}_grid.html'.format(sensor.id))

那么我在做错什么,以为图中的球体看起来只是它的一部分,或者缩小为一个平面?

0 个答案:

没有答案
相关问题