✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

How to display legends in order ? ( Pie Chart )


I’m having problems with ordering the lengends for pie chart.
I’ve thought the order is based on how it is labeled (A, B, C, D and so on in my case.)
However, it seems like it is decided by the size of its ratio in pie chart.

In short, I want to have my right-hand side legend to have [A, B, C, D, E, F] order …

Is there any way I can configure this ?

Here is my actual pie chart and the codes are below

Thanks in advance!!

                  "data": [
                      "values": by_sns_platform_1,
                      "labels": ['A', 'B', 'C', 'D', 'E', 'F'],
                      "domain": {"x": [0, .48]},
                      "name": "Published",
                      "hole": .3,
                      "type": "pie",
                      "marker" : {"colors":color_palette_1}

It looks like the only control that is available right now is the layout.legend.traceorder attribute: https://plot.ly/python/reference/#layout-legend-traceorder

Ah dang, this is a little frustrating when using Plotly express with a color faceting to produce different traces. I have a sequence of years in my legend that are not sorted, and I can’t sort them using trace_orders as that reorders the actual traces, breaking the sorting of my the already sorted x-axis values.

Looking at the link click through counts in this thread and this other related thread on this issue, this could be a friction point for a few people: Customizing the order of Legends

1 Like