gpt4 book ai didi

python - 在 plotly 3D 散点图中显示图例和标签轴

转载 作者:太空狗 更新时间:2023-10-29 18:20:20 25 4
gpt4 key购买 nike

很抱歉今天让您忙于处理阴谋问题。这是另一个:我将如何在 plotly 的新 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)

最佳答案

你很接近! 3D 轴实际上嵌入在 Scene 对象中。这是一个简单的例子:

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

trace1 = Scatter3d(
x=[1, 2],
y=[1, 2],
z=[1, 2],
name='Legendary'
)
data = Data([trace1])
layout = Layout(
showlegend=True,
scene=Scene(
xaxis=XAxis(title='x axis title'),
yaxis=YAxis(title='y axis title'),
zaxis=ZAxis(title='z axis title')
)
)

FigureWidget(data=data, layout=layout)

enter image description here 1

关于python - 在 plotly 3D 散点图中显示图例和标签轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26941135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com