将旧的 plotly 代码转换为更新的 version.I 不要 know/understand 怎么做

Converting old plotly code to newer version.I don't know/understand how to do it

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


trace1=Scatter3d(x=Xe,y=Ye,z=Ze,mode='lines',line=Line(color='rgb(125,125,125)', width=1),hoverinfo='none')

trace2=Scatter3d(x=Xn,
               y=Yn,
               z=Zn,
               mode='markers',
               name='actors',
               marker=Marker(symbol='dot',
                             color=eigen,
                             size=6,colorbar=ColorBar(
                title='Colorbar'
            ),
                             colorscale='Viridis',
                             line=Line(color='rgb(158,18,130)', width=0.5)
                             ),
               text=labels,
               hoverinfo='text'
               )

axis=dict(showbackground=False,
          showline=False,
          zeroline=False,
          showgrid=False,
          showticklabels=False,
          title=''
          )

layout = Layout(
         title="3D Visualization of the Facebook nodes",
         width=1000,
         height=1000,
         showlegend=False,
         scene=Scene(
         xaxis=XAxis(axis),
         yaxis=YAxis(axis),
         zaxis=ZAxis(axis),
        ),
     margin=Margin(
        t=100
    ),
    hovermode='closest',
    annotations=Annotations([
           Annotation(
           showarrow=False,
#             text="Data source: <a href='http://bost.ocks.org/mike/miserables/miserables.json'>[1] miserables.json</a>",
            xref='paper',
            yref='paper',
            x=0,
            y=0.1,
            xanchor='left',
            yanchor='bottom',
            font=Font(
            size=14
            )
            )
        ]),    )

data=Data([trace1, trace2])
fig=Figure(data=data, layout=layout)

py.iplot(fig)

> Blockquote

我有一段旧的 plotly 代码,我收到一条错误消息,说 plotly 已迁移到图表工作室,我刚刚开始了一个网络分析项目,为了 said/given 数据的可视化,我已经在旧版本的 plotly.Please 帮助中完成了我看到了 plotly 文档,但我不明白它的工作原理。

两个核心建议

  1. 使用字典而不是对象(即不需要 MarginData 等)
  2. 使用标准导入import plotly.graph_objects as go 提高对象范围的清晰度

我预先定义了您的代码使用的变量。 dot 不再是有效标记 symbol 替换为 square

import plotly.graph_objects as go

# define some input data...
t = np.linspace(0, 10, 50)
Xe, Ye, Ze = np.cos(t), np.sin(t), t
Xn = Xe * 2
Yn = Ye * 2
Zn = Ze * 2
eigen = t
labels = ["a"]

trace1 = go.Scatter3d(
    x=Xe,
    y=Ye,
    z=Ze,
    mode="lines",
    line=dict(color="rgb(125,125,125)", width=1),
    hoverinfo="none",
)

trace2 = go.Scatter3d(
    x=Xn,
    y=Yn,
    z=Zn,
    mode="markers",
    name="actors",
    marker=dict(
        symbol="square",
        color=eigen,
        size=6,
        colorbar=dict(title="Colorbar"),
        colorscale="Viridis",
        line=dict(color="rgb(158,18,130)", width=0.5),
    ),
    text=labels,
    hoverinfo="text",
)

axis = dict(
    showbackground=False,
    showline=False,
    zeroline=False,
    showgrid=False,
    showticklabels=False,
    title="",
)

layout = go.Layout(
    title="3D Visualization of the Facebook nodes",
    width=1000,
    height=1000,
    showlegend=False,
    scene=dict(
        xaxis=axis,
        yaxis=axis,
        zaxis=axis,
    ),
    margin={"t": 100},  # go.Margin(t=100),
    hovermode="closest",
    annotations=[
        dict(
            showarrow=False,
            text=
            "Data source: <a href='http://bost.ocks.org/mike/miserables/miserables.json'>[1] miserables.json</a>",
            xref="paper",
            yref="paper",
            x=0,
            y=0.1,
            xanchor="left",
            yanchor="bottom",
            font=dict(size=14),
        )
    ],
)

fig = go.Figure(data=[trace1, trace2], layout=layout)
fig