plotly / plotly.py

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

allow histogram marginal plot order to be reversed wrt legend #4096

Open amstaniec opened 1 year ago

amstaniec commented 1 year ago

Also in the official example: https://plotly.com/python/marginal-plots/

image

I think its confusing that the order of species (colors) is not the same in the marginal plots (above the main plot) and in the legend

AaronStiff commented 1 year ago

Hi @amstaniec. There's no way to change the marginal_x trace order, but if you'd like the order to be consistent with the legend, you can reverse the legend explicitly with

fig.update_layout(legend_traceorder="reversed")
alexcjohnson commented 1 year ago

Then the right marginal looks backward (though that's less obvious, but I'd expect top->bottom to match left -> right) Another option is to flip the top marginal:

fig.update_layout(yaxis3_autorange='reversed')

@amstaniec I do see your point, it would be better if these matched the legend order. Even if you think of this trick you need to fiddle to figure out that it's yaxis3, and if the base plot is faceted you'd need to find ALL the relevant y axes. @nicolaskruchten What do you think about flipping these axes by default? I guess it would apply to all marginal_x plots except 'histogram'?

nicolaskruchten commented 1 year ago

This problem exists pretty much everywhere due to our mostly consistent inconsistent usage of origin-is-at-the-bottom/legend-reads-top-down so I'm hesitant to special-case just marginals: stacked bar charts, stacked areas, regular (non-marginal) horizontal box plots...

image
alexcjohnson commented 1 year ago

Ah yeah, much more widespread than I realized, and particularly stacking is tricky as you couldn't fix it just by flipping the relevant axis. OK so too big a change to be able to consider a bug but perhaps a mode we could opt into (with a large effort!)