Python Plotly图例以升序显示

问题描述

我创建了一个代码,该代码显示图和图例。认情况下,图例没有特定顺序。我需要按升序排序。但是没有得到任何有用的链接。 有办法吗?

import plotly.graph_objects as go
fig = go.figure()
fig.add_trace(go.Scatter(x=time_list,y=list1,name="<b>" + entityName + "</b>",connectgaps=False))
fig.update_layout(showlegend=True,height=650,width=1400,title='<b>Availability</b>',xaxis_title='<b>Date</b>',yaxis_title='<b>Percentage</b>')
fig.show()

解决方法

您可以使用traceorder。 一个例子是:

layout = go.Layout(
   legend={'traceorder':'normal'})
)

您可以查看更详细的说明here