title: Manually defined legend in Plotly on Python
body: <p>I have some data that is broken down by day. For each day, I have a datapoint at the start and end of the day, each with a value between 0 and 100. I need to display this data as a grouped bar plot with the days on the x axis, values on the y axis and the bars colors are determined by their values. For each day, the left bar needs to have the corresponding start value, and the right bar displays the day's end value. The legend however needs to display information on the color rather than the trace
  The plot basically needs to look like this but the legend needs to display &quot;green&quot;, &quot;amber&quot;, &quot;red&quot; instead of &quot;start&quot;, &quot;end&quot;.</p>
  <p><a href="https://i.stack.imgur.com/2AEMq.png" rel="nofollow noreferrer">I need the plot to look like this but with a legend describing the colors rather than the traces</a></p>
  <p>Here is some code to reproduce the plot:</p>
  <pre><code>x = [&quot;day&quot;+str(i) for i in range(1,8)]
  starts = [10, 50, 70, 75, 20, 50, 90]
  ends = [95, 5, 80, 20, 50, 10, 75]
  starts_colors = ['green', 'orange', 'red', 'red', 'green', 'orange', 'red']
  ends_colors = ['red', 'green', 'red', 'green', 'orange', 'green', 'red']
  </code></pre>
  <p>And here is the code I have for the plot above.</p>
  <pre><code>layout = go.Layout(showlegend=True) 
  fig = go.Figure(layout=layout)
  fig.add_trace(go.Bar(x=x, y=starts, name = 'start', marker=dict(color=starts_colors)))
  fig.add_trace(go.Bar(x=x, y=ends, name = 'end', marker=dict(color=ends_colors)))
  fig.show()
  </code></pre>
  <p>If I rearrange the data into 3 traces (one for each color) with the corresponding values in starts and ends, I end up with gaps between the bars. For example &quot;day1&quot; would have a gap in the middle because there is no orange bar for &quot;day1&quot;.</p>
  <p>This seems like a simple problem but I'm at a loss as to how to get it to work the way I'm supposed to.</p>