4

Just like a similar question asked here, I would like to change the order of the legend of a plotly pie chart. The difference is that I can't simply use traceorder since I have more than 6 labels and reversing them doesn't put them in the right order.

Is there a way to customize the order?

As an example with 4 labels:

import plotly.offline as py
trace1 = go.Pie(                    
    values = [2, 4, 4, 9],                    
    labels = ['A', 'B', 'C', 'D'],
    name    = "Succes" 
)

data = [trace1]
fig  = go.Figure(data = data)
py.plot(fig)

How it's currently

I would like to prespecify the order of the legend.

4

3 回答 3

3

看起来现在唯一可用的控件是layout.legend.traceorderplotly文档中的属性

于 2019-09-17T16:36:15.177 回答
2

似乎您最好的选择是在绘制之前将输入/列重新排序为您想要的方式,因为 Plotly 将只引用该顺序。

或者

尝试使用@Massifox 提到的跟踪顺序(特别是分组)。

于 2019-09-17T16:43:13.197 回答
1

对于饼图,图例和切片顺序是链接的,默认情况下切片是排序的。要禁用排序,您可以设置sort=Falseinside go.Pie(),这将导致您的切片和相应的图例按照您在数据数组中指定的顺序出现。

于 2019-09-18T18:42:05.810 回答