plotly.py
plotly.py copied to clipboard
legend_tracegroupgap doesn't work when legend_traceorder is used
Note: to reproduce, see here
The problem
Baseline
long_df = px.data.medals_long()
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form")
fig.update_layout(width=680, height=480,)
fig.show()
works just fine:

Increasing the gap works
long_df = px.data.medals_long()
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form")
fig.update_layout(autosize=False, width=680, height=480, legend_tracegroupgap=50)
fig.show()
also works fine

Increasing the gap & reversing doesn't work
long_df = px.data.medals_long()
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form Input")
fig.update_layout(width=680,height=480, legend_traceorder="reversed", legend_tracegroupgap=50)
fig.show()
gives

Also legend groups don't work when using legend_traceorder='reversed': only one group header will show in the legend if the latter argument value is used, rather than showing all group headers in the legend (plotly version 5.18.0)
I'd place a note in the documentation of this argument, if this is confirmed in other versions.
I can confirm that increasing the gap & reversing doesn't work on Plotly version 5.21.0 codepen.