Home > Net >  White-out output when trying to get the ploty treemap and plotly sunburst
White-out output when trying to get the ploty treemap and plotly sunburst

Time:02-11

I would like to create a treemap and a sunburst of a data structure, in order to arrange the hirearchy of the data.

The data structure is stored in an excel file under two columns 'Parent' and 'Child'. This data is extracted into a pandas DataFrame named my_data. Here I have converted the data to list:

my_data_parent = ['', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'F', 'F', 'F', 'F', 'G', 'G', 'G', 'H', 'AV', 'CF', 'CF', 'EL', 'EL', 'EV', 'EV', 'MT', 'DI', 'DI', 'DI', 'DI', 'I', 'I', 'I', 'J', 'EJ', 'EJ', 'EJ', 'EJ', 'K', 'I2', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'N', 'N', 'P', 'P', 'P4', 'R', 'Q', 'Q', 'Q', 'S', 'S', 'S', 'S', 'S', 'S2', 'S2', 'S2', 'S2', 'S2', 'S2', 'S3', 'S3', 'S3', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S6', 'S6', 'S6', 'S6', 'S6', 'S6', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S8', 'S8', 'S9', 'S9', 'S9', 'S9', 'S10', 'S10', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S12', 'S12', 'S13', 'S13', 'S13', 'S13', 'S14', 'S14', 'S14', 'S14', 'S14', 'S14', 'S15', 'T', 'T1', 'T3', 'T3', 'T3', 'T3', 'T5', 'T5', 'T5', 'T6', 'T6', 'T14', 'U', 'U1', 'V', 'V', 'V5', 'V6', 'V6', 'V6', 'V7', 'V7', 'V7', 'V9', 'V9', 'V11', 'V11', 'V11', 'V11', 'W', 'W', 'X', 'X', 'X']

my_data_child = ['A', 'B', 'C', 'D', 'E', 'CS', 'SC', 'CC', 'BU', 'F', 'EA', 'G', 'H', 'Nu', 'AV', 'CF', 'EL', 'EV', 'MT', 'DTT', 'DI', 'I', 'J', 'EI', 'EJ', 'K', 'F1', 'F2', 'F3', 'F4', 'I1', 'I2', 'G1', 'L', 'M', 'N', 'N1', 'P', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10', 'R', 'Q', 'Q1', 'Q2', 'Q3', 'Q4', 'S', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'T', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'T10', 'T11', 'T12', 'T13', 'T14', 'T15', 'T16', 'T17', 'T18', 'T19', 'T20', 'T21', 'T22', 'T23', 'T24', 'T25', 'T26', 'T27', 'T28', 'T29', 'T30', 'T31', 'T32', 'T33', 'T34', 'T35', 'T36', 'T37', 'T38', 'T39', 'T40', 'T41', 'T42', 'T43', 'T44', 'T45', 'T46', 'T47', 'T48', 'T49', 'T50', 'T51', 'T52', 'T53', 'T54', 'T55', 'T56', 'T57', 'T58', 'T59', 'T60', 'T61', 'T62', 'T63', 'T64', 'U', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'U9', 'U10', 'U11', 'U12', 'U13', 'U14', 'U15', 'U16', 'U17', 'U18', 'U19', 'U20', 'U21', 'U22', 'U23', 'U24', 'U25', 'U26', 'U27', 'U28', 'U29', 'U30', 'U31', 'V', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V90', 'V9', 'V10', 'V11', 'V12', 'V13', 'V14', 'V15', 'V16', 'V17', 'V18', 'V19', 'V20', 'W', 'X', 'X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9']

Surprisingly, the following piece of code is working for every other excel file (Parent and Child datas) except the one I need. There is no error in the execution, however the output of the code is a white-out space. I wrote the treemap to html, even there there is white-out space and also in the jpg image that I downloaded.

my_labels = my_data_child
my_parents = my_data_parent

my_parents[0]=''
my_labels[0]=my_parents[1]

fig = go.Figure(go.Treemap(
    labels=np.array(my_labels),
    parents=np.array(my_parents),
    hoverinfo= 'text',
    maxdepth=2,
    #marker=dict(
     #   colorscale='RdBu',
     #   cmid=0.5),
))

fig.update_layout(margin = dict(t=0, l=0, r=0, b=0),
                 uniformtext=dict(minsize=12, 
                                 # mode='show',
                                 ),
                  width=1200, height=800
                 )
fig.show()
fig.write_html("Data_treemap.html")

The code to generate sunburst is similar. This is not the exact data I am working with. But it has the exact same structure. For the trail data I am able to get the treemap and sunburst but not for the actual data. I have invested some time in trying all combinations to make it work. Expecting to get some help here.

CodePudding user response:

Since the sample data you included has the same structure as your actual data, but the sample data can be used to produce a treemap while your actual data doesn't work, I can't think of any explanation except that your actual data must have a typo.

For example, your code with the following lists:

my_data_parent = ['', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'F', 'F', 'F', 'F', 'G', 'G', 'G', 'H', 'AV', 'CF', 'CF', 'EL', 'EL', 'EV', 'EV', 'MT', 'DI', 'DI', 'DI', 'DI', 'I', 'I', 'I', 'J', 'EJ', 'EJ', 'EJ', 'EJ', 'K', 'I2', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'N', 'N', 'P', 'P', 'P4', 'R', 'Q', 'Q', 'Q', 'S', 'S', 'S', 'S', 'S', 'S2', 'S2', 'S2', 'S2', 'S2', 'S2', 'S3', 'S3', 'S3', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S5', 'S6', 'S6', 'S6', 'S6', 'S6', 'S6', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S7', 'S8', 'S8', 'S9', 'S9', 'S9', 'S9', 'S10', 'S10', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S11', 'S12', 'S12', 'S13', 'S13', 'S13', 'S13', 'S14', 'S14', 'S14', 'S14', 'S14', 'S14', 'S15', 'T', 'T1', 'T3', 'T3', 'T3', 'T3', 'T5', 'T5', 'T5', 'T6', 'T6', 'T14', 'U', 'U1', 'V', 'V', 'V5', 'V6', 'V6', 'V6', 'V7', 'V7', 'V7', 'V9', 'V9', 'V11', 'V11', 'V11', 'V11', 'W', 'W', 'X', 'X', 'X']

my_data_child = ['A', 'B', 'C', 'D', 'E', 'CS', 'SC', 'CC', 'BU', 'F', 'EA', 'G', 'H', 'Nu', 'AV', 'CF', 'EL', 'EV', 'MT', 'DTT', 'DI', 'I', 'J', 'EI', 'EJ', 'K', 'F1', 'F2', 'F3', 'F4', 'I1', 'I2', 'G1', 'L', 'M', 'N', 'N1', 'P', 'P1', 'P2', 'P3', 'P4', 'P5', 'P6', 'P7', 'P8', 'P9', 'P10', 'R', 'Q', 'Q1', 'Q2', 'Q3', 'Q4', 'S', 'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9', 'S10', 'S11', 'S12', 'S13', 'S14', 'S15', 'T', 'T1', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7', 'T8', 'T9', 'T10', 'T11', 'T12', 'T13', 'T14', 'T15', 'T16', 'T17', 'T18', 'T19', 'T20', 'T21', 'T22', 'T23', 'T24', 'T25', 'T26', 'T27', 'T28', 'T29', 'T30', 'T31', 'T32', 'T33', 'T34', 'T35', 'T36', 'T37', 'T38', 'T39', 'T40', 'T41', 'T42', 'T43', 'T44', 'T45', 'T46', 'T47', 'T48', 'T49', 'T50', 'T51', 'T52', 'T53', 'T54', 'T55', 'T56', 'T57', 'T58', 'T59', 'T60', 'T61', 'T62', 'T63', 'T64', 'U', 'U1', 'U2', 'U3', 'U4', 'U5', 'U6', 'U7', 'U8', 'U9', 'U10', 'U11', 'U12', 'U13', 'U14', 'U15', 'U16', 'U17', 'U18', 'U19', 'U20', 'U21', 'U22', 'U23', 'U24', 'U25', 'U26', 'U27', 'U28', 'U29', 'U30', 'U31', 'V', 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', 'V7', 'V8', 'V90', 'V9', 'V10', 'V11', 'V12', 'V13', 'V14', 'V15', 'V16', 'V17', 'V18', 'V19', 'V20', 'W', 'X', 'X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9']

... produces this plot:

enter image description here

But if I create a typo by inserting a space in one of the parent labels

my_data_parent = ['', 'A', 'A ', 'A',...]

Then I do indeed get a completely blank white plot because the parent-child hierarchy no longer makes sense to plotly.

enter image description here

At this point, it's more of a debugging issue with your data than something plotly-specific, but I would encourage you to look through your actual data and make sure there are no typos like this. You said you manually mapped your actual data to your sample data - perhaps it's possible that you mapped a correct label and a label with a typo to the the same value.

One way forward could be to use python to perform a mapping from your actual labels to some new labels and see what happens.

  • Related