Hello there,
What is the difference between
marker={"colors": [myDictOfColors.get(x) for x in myLabels[1:]]}
and
layout['sunburstcolorway']=[myDictOfColors.get(x) for x in myLabels[1:]]
I tried both options and results differ but what is the logic behind ?
Let’s consider a sunburst with 3 levels :
- Level 1= center,
- Level 2 = children,
- Level 3 = subchildren
With sunburstcolorway,
It looks like element of list “sunburstcolorway” are applied to each children, but not on the center. Then, subchildren keep the same color but opacity is reduced.
Problem is, when the sunburst figure is generated, childrens are aggregated by unique value, and the list of colors does not match to anything anymore
With colors defined as below:
marker = {
"line": {"width":2},
"colors": [myDictOfColors.get(x) for x in myLabels[1:]]
},
I can define one specific color for each label, but the problem remains; when the figure is generated, the order changes, and the list of color does not match to anything anymore.
If it’s really what happens, then it seems strange to me, because if I define my sunburst like this:
myParents=[""," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," COUNTRY"," F"," C"," M"," C"," V"," C"," K"," N"," A"," M"," R"," Frd"," S"," S"," B"," Mit"," H"," J"," H"," N"," T"," T"," T"," T"," K"," V"," R"," O]
myLabels= ["COUNTRY"," F"," M"," A"," H"," K"," B"," T"," Frd"," J"," Mit"," O"," C"," S"," N"," V"," R"," F_a"," C_c"," M_a"," C_a"," V_b"," C_b"," K_a"," N_b"," A_a"," M_b"," R_b"," Frd_a"," S_a"," S_b"," B_a"," Mit_a"," H_b"," J_a"," H_a"," N_a"," T_a"," T_b"," T_c"," T_d"," K_b"," V_a"," R_a"," O_a"]
myValues= [169949, 0, 66, 1542, 11169, 6331, 14523, 23733, 125, 5499, 294, 1807, 1865, 10117, 31188, 18297, 33224, 0, 523, 66, 1071, 16319, 271, 1090, 1380, 1542, 0, 0, 125, 3596, 6521, 14523, 294, 7285, 5499, 3884, 29808, 13201, 10457, 75, 0, 5241, 1978, 33224, 1807]
myColors= ["#fef7df"," #BEBADA"," #fef7df"," pink"," #FCCDE5"," #E5C494"," #E82127"," #fef7df"," #fef7df"," #fef7df"," #FFFFB3"," #CCEBC5"," #FFED6F"," #FDB462"," #fef7df"," #BC80BD"," #fef7df"," #1fa230"," #2f4b7c"," #17cc39"," #006766"," #207a27"," #faa2d4"," #ffbc6c"," #737584"," #1e3152"," #a05195"," #ffd6ae"," #ffeb09"," #c3b404"," #1f5bcc"," #d45087"," #cca680"," #daff6c"," #6acff7"," #ff8500"," #f95d6a"," #f2ae9c"," #cc0000"," #eeeeee"," #e700a2"," #4dcac8"," #5c1fcc"," #ff7c43"," #6d4f2d]
traces=[(go.Sunburst(
parents=myParents,
labels=myLabels,
values=myValues
domain={'x': [0,1], 'y': [0, 1]},
textinfo="label+value",
branchvalues="total",
outsidetextfont = {"size": 20, "color": "#377eb8"},
marker = {
"line": {"width":2},
"colors": myColors
},
))]
The values are not messed up. So, if values are not messed up, why colors are ?
Is there a way to link specific color to a specific label, so that things dont mess up when the order change ?
Edit:im going to sort myLabels, myParents, myValues, before generating the graph. Should fix the prob
Edit2: partial answer here https://plot.ly/r/reference/#layout-extendsunburstcolors
Edit3: Problem fixed by sorting the relevant dicts
first step : given that each parents is the sum of its children, sort this dict by value (DESC) and then by key (ASC) (in case 2 parents have the same value).
second step: remove the pair (key, value) from the dict if value==0
third step: sort each children dict by value (DESC) and then by key( ASC)
rest of the process is straightforward once everything has been sorted