plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
15.97k stars 2.54k forks source link

legend_tracegroupgap doesn't work when legend_traceorder is used #3801

Open imirzadeh opened 2 years ago

imirzadeh commented 2 years ago

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: newplot (3)

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 newplot (4)

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 newplot (5)

matanox commented 2 months ago

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.

Coding-with-Adam commented 2 months ago

I can confirm that increasing the gap & reversing doesn't work on Plotly version 5.21.0 codepen.