title: Customizing the order of legends in plotly
body: <p>I am trying to customize the order of legends while plotting stacked bar plots in plotly,python.</p>
  
  <pre><code>data = [
          go.Bar(
              y=df['sid'],  # assign x as the dataframe column 'x'
              x=df['A'],
              orientation='h',
              name='A'
          ),
          go.Bar(
              y=df['sid'],
              x=df['B'],
              orientation='h',
              name='B'
          ),
  
      ]
  
      layout = go.Layout(
          barmode='stack',
          title=f'{measurement}',
          xaxis=dict(
              title='Count',
              dtick=0),
          yaxis=dict(
              tickfont=dict(
                  size=10,
              ),
              dtick=1)
      )
  
      fig = go.Figure(data=data, layout=layout)
      plot(fig, filename='plot.html')
  </code></pre>
  
  <p>The order of the legend appears in the reverse order(i.e from bottom to top). I want to change the order from top to bottom of the corresponding items in <code>data</code>.</p>
  
  <p>I saw the option suggested <a href="https://community.plot.ly/t/customizing-the-order-of-legends/12668" rel="noreferrer">here</a> for java. Not sure how to implement in python.</p>
  
  <p>Could someone suggest how the order can be reversed?</p>
  
  <p>EDIT:
  In the image that is generated the order of legend is</p>
  
  <pre><code>B
  A
  </code></pre>
  
  <p>Desired order:</p>
  
  <pre><code>A
  B
  </code></pre>