Plotly 3D 散点图、轴标签、悬停和图例版

时间:2021-07-06 23:54:23

标签: hover axis-labels plotly-python legend-properties

我有以下数据框:

enter image description here

我想绘制主成分的 3D 散点图。类似的东西:

enter image description here

我一直在纠结剧情属性的版本。我想知道:

  1. 如何编辑悬停以打印 Muestra,pc1,pc2,pc3 而不是 x,y,z?
  2. 如何在情节外添加图例?
  3. 如何编辑轴的名称?

代码:

import pandas as pd
import string
import plotly.graph_objects as go

df = pd.DataFrame(
    {
        "pc1": range(11),
        "pc2": range(10, -1, -1),
        'pc3': range(35,46),
        "Muestra": list(string.ascii_uppercase[:11]),
        "color": ["#cf0c0c"] * 6 + ["#0dab51"] * 5,
    },
    index=range(1, 12))

data = go.Scatter3d(x=df.pc1,
                    y=df.pc2,
                    z=df.pc3,
                    mode='markers',
                    marker=dict(size=10, color=df.color, opacity=0.8))

fig = go.Figure(data=[data])

# tight layout
fig.update_layout(margin=dict(l=0, r=0, b=0, t=0))
fig.show()

0 个答案:

没有答案