Hi
I am using plotly express to produce a sunburst plot of datas. I succeed to make one plot to work, but If I change with another data set the plot is not displayed. I did not get any error message or warning. When I produce the plot it appears empty.
Here is the code I use:
fig2 = px.sunburst(
class_data2,
names='Chem. Class',
parents='Chem. Group',
values='Intensity',
branchvalues="total",
)
fig2.update_traces(
hovertemplate="<br>".join([
"Chem. Class: %{label}",
"Chem. Group: %{parent}",
"Intensity: %{value:.2f}%",
])
)
fig2.update_layout(
height=800,
width=800,
title=dict(text="Chemical class"),
plot_bgcolor='white',
)
Hereafter are the details of the figure and the data.
Thanks
The plot with these figure works well
Figure({
'data': [{'branchvalues': 'total',
'domain': {'x': [0.0, 1.0], 'y': [0.0, 1.0]},
'hovertemplate': 'Chem. Class: %{label}<br>Chem. Group: %{parent}<br>Intensity: %{value:.2f}%',
'labels': array(['Sample', 'N', 'N P', 'N P S', 'N S', 'O', 'O B', 'O N', 'O N P',
'O N P S', 'O N S', 'O P', 'O P S', 'O S', 'P', 'P S', 'N1', 'N2',
'N1 P1', 'N3 P1', 'N1 P1 S2', 'N3 P2 S1', 'N3 S2', 'O1', 'O10', 'O11',
'O12', 'O13', 'O14', 'O15', 'O16', 'O17', 'O18', 'O19', 'O2', 'O20',
'O21', 'O22', 'O27', 'O3', 'O4', 'O5', 'O6', 'O7', 'O8', 'O9', 'O10 B1',
'O11 B1', 'O12 B1', 'O22 B1', 'O1 N1', 'O1 N2', 'O1 N3', 'O10 N2',
'O15 N2', 'O2 N5', 'O20 N2', 'O22 N3', 'O3 N1', 'O4 N1', 'O4 N5',
'O5 N1', 'O5 N4', 'O5 N5', 'O6 N5', 'O7 N1', 'O7 N5', 'O8 N4', 'O9 N4',
'O1 N4 P2', 'O10 N5 P1', 'O15 N3 P2', 'O17 N1 P2', 'O2 N2 P1',
'O2 N2 P2', 'O2 N5 P1', 'O3 N2 P1', 'O6 N1 P1', 'O7 N5 P1',
'O1 N3 P1 S1', 'O1 N4 P1 S1', 'O1 N4 P1 S2', 'O11 N5 P2 S2',
'O12 N4 P1 S2', 'O15 N5 P1 S2', 'O17 N1 P1 S2', 'O18 N5 P1 S1',
'O2 N2 P2 S1', 'O26 N2 P2 S2', 'O3 N3 P1 S1', 'O3 N3 P2 S1',
'O4 N2 P1 S2', 'O4 N3 P2 S1', 'O4 N4 P2 S2', 'O5 N1 P1 S1',
'O5 N2 P2 S1', 'O5 N3 P2 S1', 'O5 N5 P2 S1', 'O6 N3 P2 S2',
'O8 N5 P2 S2', 'O10 N1 S1', 'O2 N1 S1', 'O2 N4 S1', 'O2 N4 S2',
'O2 N5 S2', 'O3 N5 S2', 'O4 N2 S1', 'O4 N4 S1', 'O6 N4 S2', 'O9 N4 S1',
'O1 P2', 'O10 P2', 'O14 P1', 'O3 P2', 'O6 P1', 'O6 P2', 'O1 P1 S1',
'O1 P2 S2', 'O3 P1 S2', 'O7 P2 S2', 'O1 S1', 'O20 S2', 'O21 S2',
'O23 S1', 'O24 S1', 'O3 S1', 'O4 S1', 'O5 S1', 'O6 S1', 'P1', 'P1 S1',
'P2 S2'], dtype=object),
'name': '',
'parents': array(['', 'Sample', 'Sample', 'Sample', 'Sample', 'Sample', 'Sample',
'Sample', 'Sample', 'Sample', 'Sample', 'Sample', 'Sample', 'Sample',
'Sample', 'Sample', 'N', 'N', 'N P', 'N P', 'N P S', 'N P S', 'N S',
'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O',
'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O B', 'O B', 'O B', 'O B',
'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N',
'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N P',
'O N P', 'O N P', 'O N P', 'O N P', 'O N P', 'O N P', 'O N P', 'O N P',
'O N P', 'O N P S', 'O N P S', 'O N P S', 'O N P S', 'O N P S',
'O N P S', 'O N P S', 'O N P S', 'O N P S', 'O N P S', 'O N P S',
'O N P S', 'O N P S', 'O N P S', 'O N P S', 'O N P S', 'O N P S',
'O N P S', 'O N P S', 'O N P S', 'O N P S', 'O N S', 'O N S', 'O N S',
'O N S', 'O N S', 'O N S', 'O N S', 'O N S', 'O N S', 'O N S', 'O P',
'O P', 'O P', 'O P', 'O P', 'O P', 'O P S', 'O P S', 'O P S', 'O P S',
'O S', 'O S', 'O S', 'O S', 'O S', 'O S', 'O S', 'O S', 'O S', 'P',
'P S', 'P S'], dtype=object),
'type': 'sunburst',
'values': array([1.00000000e+02, 3.18809913e-02, 2.92167982e-02, 4.26895032e-02,
1.46620044e-02, 9.67547096e+01, 1.15136521e-01, 8.25492897e-01,
1.96966303e-01, 6.99652536e-01, 5.62363794e-01, 1.53396019e-01,
6.19683627e-02, 4.70006871e-01, 1.36306114e-02, 2.82272244e-02,
1.37702333e-02, 1.81107580e-02, 1.56108020e-02, 1.36059963e-02,
2.78906995e-02, 1.47988037e-02, 1.46620044e-02, 2.28014169e-01,
9.80651178e+00, 9.33377494e+00, 9.10272723e+00, 8.38799750e+00,
7.45881220e+00, 6.67072496e+00, 5.29114494e+00, 4.02946349e+00,
2.58349032e+00, 1.49098965e+00, 1.98607723e+00, 5.94099297e-01,
1.53694082e-01, 1.46038700e-02, 1.97566991e-02, 4.73493875e-01,
1.13777616e+00, 1.76579320e+00, 3.80201310e+00, 6.01601167e+00,
7.56793941e+00, 8.83979981e+00, 5.09256675e-02, 1.37371741e-02,
3.72066357e-02, 1.32670438e-02, 4.99689533e-02, 2.95908680e-02,
4.09180512e-02, 1.32575331e-02, 1.41633046e-02, 5.57600093e-02,
1.32032800e-02, 1.50720883e-02, 1.16922240e-01, 1.46297749e-02,
2.01250305e-01, 2.67285137e-02, 2.64967343e-02, 7.98999689e-02,
5.63700638e-02, 1.46531120e-02, 1.61258210e-02, 2.14891742e-02,
1.89931015e-02, 1.41407674e-02, 1.51441401e-02, 3.34277510e-02,
1.74285727e-02, 1.53895603e-02, 1.38940534e-02, 4.54493992e-02,
1.42553792e-02, 1.42871959e-02, 1.35494835e-02, 1.81932943e-02,
1.36167217e-02, 1.32424386e-02, 1.44336224e-02, 1.55331958e-02,
4.18284861e-02, 1.52239209e-02, 1.40591042e-02, 2.86257157e-02,
1.39977719e-02, 1.35685423e-02, 2.34630228e-01, 1.38860203e-02,
9.94161956e-02, 1.32525694e-02, 1.38056686e-02, 1.38797667e-02,
6.38242254e-02, 1.58778350e-02, 1.44765220e-02, 1.42806915e-02,
1.46985715e-02, 4.35011941e-01, 1.32481805e-02, 1.33513281e-02,
1.44504907e-02, 1.35491793e-02, 1.46638750e-02, 1.50484865e-02,
1.40798933e-02, 1.42618480e-02, 1.47112801e-02, 1.39434476e-02,
1.31277656e-02, 1.45830789e-02, 2.98687311e-02, 6.71617153e-02,
1.69063264e-02, 1.57165450e-02, 1.36556413e-02, 1.56898500e-02,
1.39032560e-02, 6.19696959e-02, 1.45648872e-02, 1.27793803e-01,
1.41427071e-02, 1.58840379e-01, 4.40057062e-02, 1.72135609e-02,
1.75728759e-02, 1.36306114e-02, 1.42226973e-02, 1.40045271e-02])}],
'layout': {'height': 800,
'legend': {'tracegroupgap': 0},
'margin': {'t': 60},
'plot_bgcolor': 'white',
'template': '...',
'title': {'text': 'Chemical class'},
'width': 800}
})
The one with this data does not display
Figure({
'data': [{'branchvalues': 'total',
'domain': {'x': [0.0, 1.0], 'y': [0.0, 1.0]},
'hovertemplate': 'Chem. Class: %{label}<br>Chem. Group: %{parent}<br>Intensity: %{value:.2f}%',
'labels': array(['Sample', 'HC', 'N', 'O', 'O N', 'HC', 'N1', 'N10', 'N11', 'N12', 'N13',
'N14', 'N16', 'N17', 'N18', 'N19', 'N2', 'N21', 'N22', 'N24', 'N25',
'N3', 'N4', 'N5', 'N6', 'N7', 'N8', 'N9', 'O1', 'O2', 'O1 N1', 'O1 N10',
'O1 N11', 'O1 N12', 'O1 N13', 'O1 N15', 'O1 N16', 'O1 N17', 'O1 N18',
'O1 N19', 'O1 N2', 'O1 N21', 'O1 N22', 'O1 N23', 'O1 N24', 'O1 N3',
'O1 N4', 'O1 N5', 'O1 N6', 'O1 N7', 'O1 N8', 'O1 N9', 'O2 N1', 'O2 N10',
'O2 N11', 'O2 N12', 'O2 N13', 'O2 N14', 'O2 N15', 'O2 N16', 'O2 N17',
'O2 N18', 'O2 N19', 'O2 N2', 'O2 N20', 'O2 N21', 'O2 N22', 'O2 N23',
'O2 N25', 'O2 N3', 'O2 N4', 'O2 N5', 'O2 N6', 'O2 N7', 'O2 N8', 'O2 N9'],
dtype=object),
'name': '',
'parents': array(['', 'Sample', 'Sample', 'Sample', 'Sample', 'HC', 'N', 'N', 'N', 'N',
'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N',
'N', 'N', 'N', 'N', 'O', 'O', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N',
'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N',
'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N',
'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N',
'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N', 'O N'],
dtype=object),
'type': 'sunburst',
'values': array([1.00000000e+02, 2.06984421e-03, 8.14331831e+01, 5.16101237e-01,
1.80486458e+01, 2.06984421e-03, 3.92348209e-02, 3.76744360e+00,
1.93989189e+00, 7.21437493e-01, 1.60734505e-01, 1.19366957e-01,
2.00749222e-03, 2.38382315e-03, 2.85763762e-03, 2.08162201e-03,
1.08287709e+00, 1.02619907e-02, 8.57400202e-03, 5.17948452e-03,
2.11038228e-03, 4.41011282e+00, 1.03133471e+01, 1.33488771e+01,
1.65070029e+01, 1.32545851e+01, 9.62275964e+00, 6.11005570e+00,
3.32651323e-01, 1.83449914e-01, 2.50077456e-01, 5.74465766e-01,
2.04417217e-01, 4.82234869e-02, 6.92281670e-03, 2.86325866e-03,
6.35544377e-03, 2.10511032e-03, 3.96098278e-03, 4.57085631e-03,
3.57066880e-01, 6.48182277e-02, 1.68095378e-02, 1.00146735e-02,
1.56710420e-02, 7.97102970e-01, 1.49881192e+00, 2.57221192e+00,
2.91739716e+00, 2.21285699e+00, 1.62370025e+00, 1.05056226e+00,
7.83627733e-02, 1.50059531e-01, 7.87875559e-02, 2.45140038e-02,
2.32630262e-02, 8.51267903e-02, 6.84593478e-03, 8.48734293e-03,
3.53338010e-02, 2.68777991e-02, 2.02809511e-03, 3.87544879e-02,
2.42893371e-03, 1.53025854e-02, 2.17183170e-02, 7.24044144e-03,
4.42502261e-03, 1.95208955e-01, 4.70335994e-01, 7.29997010e-01,
7.45506590e-01, 4.68943696e-01, 3.18149951e-01, 2.69960980e-01])}],
'layout': {'height': 800,
'legend': {'tracegroupgap': 0},
'margin': {'t': 60},
'plot_bgcolor': 'white',
'template': '...',
'title': {'text': 'Chemical class'},
'width': 800}
})
Here is the dataframe for which it does not work
Chem. Group Chem. Class Intensity cumsum
0 Sample 100.000000 NaN
1 Sample HC 0.002070 NaN
2 Sample N 81.433183 NaN
3 Sample O 0.516101 NaN
4 Sample O N 18.048646 NaN
0 HC HC 0.002070 0.002070
1 N N1 0.039235 0.041305
2 N N10 3.767444 3.808748
3 N N11 1.939892 5.748640
4 N N12 0.721437 6.470078
5 N N13 0.160735 6.630812
6 N N14 0.119367 6.750179
7 N N16 0.002007 6.752187
8 N N17 0.002384 6.754570
9 N N18 0.002858 6.757428
10 N N19 0.002082 6.759510
11 N N2 1.082877 7.842387
12 N N21 0.010262 7.852649
13 N N22 0.008574 7.861223
14 N N24 0.005179 7.866402
15 N N25 0.002110 7.868513
16 N N3 4.410113 12.278625
17 N N4 10.313347 22.591973
18 N N5 13.348877 35.940850
19 N N6 16.507003 52.447853
20 N N7 13.254585 65.702438
21 N N8 9.622760 75.325197
22 N N9 6.110056 81.435253
23 O O1 0.332651 81.767904
24 O O2 0.183450 81.951354
25 O N O1 N1 0.250077 82.201432
26 O N O1 N10 0.574466 82.775897
27 O N O1 N11 0.204417 82.980315
28 O N O1 N12 0.048223 83.028538
29 O N O1 N13 0.006923 83.035461
30 O N O1 N15 0.002863 83.038324
31 O N O1 N16 0.006355 83.044680
32 O N O1 N17 0.002105 83.046785
33 O N O1 N18 0.003961 83.050746
34 O N O1 N19 0.004571 83.055317
35 O N O1 N2 0.357067 83.412383
36 O N O1 N21 0.064818 83.477202
37 O N O1 N22 0.016810 83.494011
38 O N O1 N23 0.010015 83.504026
39 O N O1 N24 0.015671 83.519697
40 O N O1 N3 0.797103 84.316800
41 O N O1 N4 1.498812 85.815612
42 O N O1 N5 2.572212 88.387824
43 O N O1 N6 2.917397 91.305221
44 O N O1 N7 2.212857 93.518078
45 O N O1 N8 1.623700 95.141778
46 O N O1 N9 1.050562 96.192340
47 O N O2 N1 0.078363 96.270703
48 O N O2 N10 0.150060 96.420763
49 O N O2 N11 0.078788 96.499550
50 O N O2 N12 0.024514 96.524064
51 O N O2 N13 0.023263 96.547327
52 O N O2 N14 0.085127 96.632454
53 O N O2 N15 0.006846 96.639300
54 O N O2 N16 0.008487 96.647787
55 O N O2 N17 0.035334 96.683121
56 O N O2 N18 0.026878 96.709999
57 O N O2 N19 0.002028 96.712027
58 O N O2 N2 0.038754 96.750782
59 O N O2 N20 0.002429 96.753210
60 O N O2 N21 0.015303 96.768513
61 O N O2 N22 0.021718 96.790231
62 O N O2 N23 0.007240 96.797472
63 O N O2 N25 0.004425 96.801897
64 O N O2 N3 0.195209 96.997106
65 O N O2 N4 0.470336 97.467442
66 O N O2 N5 0.729997 98.197439
67 O N O2 N6 0.745507 98.942945
68 O N O2 N7 0.468944 99.411889
69 O N O2 N8 0.318150 99.730039
70 O N O2 N9 0.269961 100.000000
This is the one which works
0 Sample 100.000000 NaN
1 Sample N 0.031881 NaN
2 Sample N P 0.029217 NaN
3 Sample N P S 0.042690 NaN
4 Sample N S 0.014662 NaN
5 Sample O 96.754710 NaN
6 Sample O B 0.115137 NaN
7 Sample O N 0.825493 NaN
8 Sample O N P 0.196966 NaN
9 Sample O N P S 0.699653 NaN
10 Sample O N S 0.562364 NaN
11 Sample O P 0.153396 NaN
12 Sample O P S 0.061968 NaN
13 Sample O S 0.470007 NaN
14 Sample P 0.013631 NaN
15 Sample P S 0.028227 NaN
0 N N1 0.013770 0.013770
1 N N2 0.018111 0.031881
2 N P N1 P1 0.015611 0.047492
3 N P N3 P1 0.013606 0.061098
4 N P S N1 P1 S2 0.027891 0.088988
5 N P S N3 P2 S1 0.014799 0.103787
6 N S N3 S2 0.014662 0.118449
7 O O1 0.228014 0.346463
8 O O10 9.806512 10.152975
9 O O11 9.333775 19.486750
10 O O12 9.102727 28.589477
11 O O13 8.387997 36.977475
12 O O14 7.458812 44.436287
13 O O15 6.670725 51.107012
14 O O16 5.291145 56.398157
15 O O17 4.029463 60.427620
16 O O18 2.583490 63.011111
17 O O19 1.490990 64.502100
18 O O2 1.986077 66.488178
19 O O20 0.594099 67.082277
20 O O21 0.153694 67.235971
21 O O22 0.014604 67.250575
22 O O27 0.019757 67.270332
23 O O3 0.473494 67.743826
24 O O4 1.137776 68.881602
25 O O5 1.765793 70.647395
26 O O6 3.802013 74.449408
27 O O7 6.016012 80.465420
28 O O8 7.567939 88.033359
29 O O9 8.839800 96.873159
30 O B O10 B1 0.050926 96.924085
31 O B O11 B1 0.013737 96.937822
32 O B O12 B1 0.037207 96.975028
33 O B O22 B1 0.013267 96.988295
34 O N O1 N1 0.049969 97.038264
35 O N O1 N2 0.029591 97.067855
36 O N O1 N3 0.040918 97.108773
37 O N O10 N2 0.013258 97.122031
38 O N O15 N2 0.014163 97.136194
39 O N O2 N5 0.055760 97.191954
40 O N O20 N2 0.013203 97.205157
41 O N O22 N3 0.015072 97.220229
42 O N O3 N1 0.116922 97.337152
43 O N O4 N1 0.014630 97.351781
44 O N O4 N5 0.201250 97.553032
45 O N O5 N1 0.026729 97.579760
46 O N O5 N4 0.026497 97.606257
47 O N O5 N5 0.079900 97.686157
48 O N O6 N5 0.056370 97.742527
49 O N O7 N1 0.014653 97.757180
50 O N O7 N5 0.016126 97.773306
51 O N O8 N4 0.021489 97.794795
52 O N O9 N4 0.018993 97.813788
53 O N P O1 N4 P2 0.014141 97.827929
54 O N P O10 N5 P1 0.015144 97.843073
55 O N P O15 N3 P2 0.033428 97.876501
56 O N P O17 N1 P2 0.017429 97.893930
57 O N P O2 N2 P1 0.015390 97.909319
58 O N P O2 N2 P2 0.013894 97.923213
59 O N P O2 N5 P1 0.045449 97.968663
60 O N P O3 N2 P1 0.014255 97.982918
61 O N P O6 N1 P1 0.014287 97.997205
62 O N P O7 N5 P1 0.013549 98.010755
63 O N P S O1 N3 P1 S1 0.018193 98.028948
64 O N P S O1 N4 P1 S1 0.013617 98.042565
65 O N P S O1 N4 P1 S2 0.013242 98.055807
66 O N P S O11 N5 P2 S2 0.014434 98.070241
67 O N P S O12 N4 P1 S2 0.015533 98.085774
68 O N P S O15 N5 P1 S2 0.041828 98.127602
69 O N P S O17 N1 P1 S2 0.015224 98.142826
70 O N P S O18 N5 P1 S1 0.014059 98.156885
71 O N P S O2 N2 P2 S1 0.028626 98.185511
72 O N P S O26 N2 P2 S2 0.013998 98.199509
73 O N P S O3 N3 P1 S1 0.013569 98.213077
74 O N P S O3 N3 P2 S1 0.234630 98.447708
75 O N P S O4 N2 P1 S2 0.013886 98.461594
76 O N P S O4 N3 P2 S1 0.099416 98.561010
77 O N P S O4 N4 P2 S2 0.013253 98.574262
78 O N P S O5 N1 P1 S1 0.013806 98.588068
79 O N P S O5 N2 P2 S1 0.013880 98.601948
80 O N P S O5 N3 P2 S1 0.063824 98.665772
81 O N P S O5 N5 P2 S1 0.015878 98.681650
82 O N P S O6 N3 P2 S2 0.014477 98.696126
83 O N P S O8 N5 P2 S2 0.014281 98.710407
84 O N S O10 N1 S1 0.014699 98.725106
85 O N S O2 N1 S1 0.435012 99.160118
86 O N S O2 N4 S1 0.013248 99.173366
87 O N S O2 N4 S2 0.013351 99.186717
88 O N S O2 N5 S2 0.014450 99.201168
89 O N S O3 N5 S2 0.013549 99.214717
90 O N S O4 N2 S1 0.014664 99.229381
91 O N S O4 N4 S1 0.015048 99.244429
92 O N S O6 N4 S2 0.014080 99.258509
93 O N S O9 N4 S1 0.014262 99.272771
94 O P O1 P2 0.014711 99.287482
95 O P O10 P2 0.013943 99.301426
96 O P O14 P1 0.013128 99.314553
97 O P O3 P2 0.014583 99.329136
98 O P O6 P1 0.029869 99.359005
99 O P O6 P2 0.067162 99.426167
100 O P S O1 P1 S1 0.016906 99.443073
101 O P S O1 P2 S2 0.015717 99.458790
102 O P S O3 P1 S2 0.013656 99.472445
103 O P S O7 P2 S2 0.015690 99.488135
104 O S O1 S1 0.013903 99.502039
105 O S O20 S2 0.061970 99.564008
106 O S O21 S2 0.014565 99.578573
107 O S O23 S1 0.127794 99.706367
108 O S O24 S1 0.014143 99.720510
109 O S O3 S1 0.158840 99.879350
110 O S O4 S1 0.044006 99.923356
111 O S O5 S1 0.017214 99.940569
112 O S O6 S1 0.017573 99.958142
113 P P1 0.013631 99.971773
114 P S P1 S1 0.014223 99.985995
115 P S P2 S2 0.014005 100.000000