[Python] Show legend and label axes in plotly 3D scatter plots

Discussão em 'Python' iniciado por Stack, Maio 29, 2025.

  1. Stack

    Stack Membro Participativo

    Sorry for keeping you busy with plotly questions today. Here would be another one: How would I show the legend and axes labels on plotly's new 3D scatter plots?

    E.g., if I have the following scatter plot in 2D that produced everything fine, I added another dimension but the axes labels don't show anymore (see code below), and the same problem with the legend. Any tips? Thanks!

    [​IMG]

    [​IMG]

    traces = []

    for name in ('Iris-setosa', 'Iris-versicolor', 'Iris-virginica'):

    trace = Scatter3d(
    x=Y[y==name,0],
    y=Y[y==name,1],
    z=Y[y==name,2],
    mode='markers',
    name=name,
    marker=Marker(
    size=12,
    line=Line(
    color='rgba(217, 217, 217, 0.14)',
    width=0.5
    ),
    opacity=0.8
    )

    )
    traces.append(trace)


    data = Data(traces)
    layout = Layout(xaxis=XAxis(title='PC1'),
    yaxis=YAxis(title='PC2'),
    zaxis=ZAxis(title='PC3')
    )
    fig = Figure(data=data, layout=layout)
    py.iplot(fig)

    Continue reading...

Compartilhe esta Página