2014-11-15 8 views
8

오늘은 음탕 한 질문으로 바쁘게 지 않으니 죄송합니다. 음모의 새로운 3D 산점도에 범례와 축 레이블을 어떻게 표시 할 수 있습니까?범례 3D 축 산점도로 범례 및 레이블 축 표시

예 : 2D에서 다음과 같은 분산 형 플롯을 사용해도 괜찮 았지만, 다른 치수를 추가했지만 축 레이블이 더 이상 표시되지 않고 (아래 코드 참조) 범례와 동일한 문제가 발생했습니다. 어떤 팁? 감사!

enter image description here

enter image description here

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) 

답변

16

당신이 가까이있어! 3D 축은 실제로 Scene 개체에 포함되어 있습니다.

import plotly.plotly as py 
from plotly.graph_objs import * 

trace1 = Scatter3d(
    x=[1, 2], 
    y=[1, 2], 
    z=[1, 2] 
) 
data = Data([trace1]) 
layout = Layout(
    scene=Scene(
     xaxis=XAxis(title='x axis title'), 
     yaxis=YAxis(title='y axis title'), 
     zaxis=ZAxis(title='z axis title') 
    ) 
) 
fig = Figure(data=data, layout=layout) 
plot_url = py.plot(fig, filename='3d-scatter-with-axes-titles') 
다음

enter image description here

+0

다시 한 번 감사드립니다. Chris! 그리고'Scene'이 적절히 설정되면 전설은 "showlegend = True"를 통해 너무 잘 보여 질 수 있습니다. – Sebastian

관련 문제