1

I have created a code which displays a graph along with legend. The legend by default is not in any specific order. I need to order it in ascending order. But did not get any useful link for that. Is there a way to do that?

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()
Nirmal Ram
  • 1,180
  • 2
  • 9
  • 18

1 Answers1

0

You can use traceorder. An example would be:

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

You can view a more detailed explanation here.

Landon
  • 119
  • 11
  • "normal" - the items are displayed top-to-bottom in the same order as the input data. Traceorder is not helping here. – Nirmal Ram Aug 11 '20 at 17:24