【问题标题】:How to change the name of variables when adding more than one line plot [duplicate]添加多个线图时如何更改变量的名称[重复]
【发布时间】:2021-08-07 13:42:52
【问题描述】:

我用 Plotly 创建了一个两线图,当 showlegend=True 时,变量的名称是 Trace 0 和 Trace 1。如何手动更改这些变量的名称?

我在下面显示代码和输出。

# add line / trace 1 to fig_linee2
    fig_linee2 = go.Figure()
    fig_linee2.add_trace(go.Scatter(
    x=Deaths_wihing_28_days2["date"],
    y=Deaths_wihing_28_days2['newDeaths28DaysByDeathDate'],

    marker=dict(
        color="blue"
    ),
    showlegend=True
))

# add line / trace 2 to fig_linee2

    fig_linee2.add_trace(go.Scatter(
    x=patients_adm2["date"],
    y=patients_adm2["newAdmissions"],

    marker=dict(
        color="green"
    ),
    showlegend=True))

    fig_linee2.update_layout(
    height=400,
    title=dict(
        text='<b>Death people and admitted by COVID</b>', 
        x=0.5,
        y=0.95,
        font=dict(
            family="Arial",
            size=20,
            color='#000000'
        )
    ),
    xaxis_title="<b>Selected date</b>",
    yaxis_title='<b>Number of people</b>',
    font=dict(
        family="Courier New, Monospace",
        size=12,
        color='#000000'),
        
)




【问题讨论】:

    标签: python plotly


    【解决方案1】:

    将“name”参数添加到go.Scatter(x=.., y=...,name=..., ...)

    见Manual Labelling with Graph Objects in the doc

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 2021-01-29
      • 2023-03-04
      相关资源
      最近更新 更多