Black Lives Matter. Please consider donating to Black Girls Code today.

Sunburst branchvalues parameter

@Dmrks in your spreadsheet screenshot above, rows 2 and 3 appear to have duplicate IDs… ?

Apologies, so I slightly edited the data as some of is sensitive. In that case there’s two projects that share the same first name. E.g. BSTD project1 BSTD project2

I’ve re-run the original script without any duplicates, still having the same issue.

OK. I still can’t reproduce this problem locally so if anyone can post a replicable example I’d be grateful :slight_smile:

I’ve tried the sample data from https://community.plotly.com/t/26582 (over in the R forum) but those all work in Python with Plotly v4.2.1:

import plotly.graph_objects as go
go.Figure(
    go.Sunburst(
        labels = ["Seth", "Enos", "Noam", "Awan", "Enoch"],
        parents = ["", "Seth", "Seth", "", "Awan"],
        values = [12, 10, 2, 4, 4],
        branchvalues="total"
    )
)

and

import plotly.graph_objects as go
go.Figure(
    go.Sunburst(
ids = [1, 2, 3, 4, 5, 6, 7, 8, 9, "1 - a", "1 - b", "2 - a", "2 - b", "3 - a", "3 - b", "4 - b", "5 - a", "5 - b", "6 - a", "6 - b", "7 - a", "7 - b", "8 - a", "8 - b", "9 - a", "9 - b"],
labels = ["Group 1", "Group 2", "Group 3", "Group 4", "Group 5", "Group 6", "Group 7", "Group 8", "Group 9", "a", "b", "a", "b", "a", "b", "b", "a", "b", "a", "b", "a", "b", "a", "b", "a", "b"],
parents = ["", "", "", "", "", "", "", "", "","1", "1", "2", "2", "3", "3", "4", "5", "5", "6", "6", "7", "7", "8", "8", "9", "9"],
values = [195, 99, 2425, 3, 379, 5182, 48, 3119, 903, 37, 158, 15, 84, 561, 1864, 3, 67, 312, 915, 4267, 19, 29, 433, 2686, 51, 852]
       , branchvalues="total"
    )
)

If you’re able to look in the Javascript console, it usually gives a helpful-ish error when this fails, like this for example:

1 Like

Thanks, this is helpful as what I found most difficult about working with Plotly is not getting error messages to aid debugging.

How do I access the JavaScript console in R? I’ve had a quick Google

I also had this issue. I found that plotly is temperamental when it came to float values. When I rounded them to ints, it worked fine

Someone else from my organisation has also come to me with the same issue. Which is a shame as it is one of the best sunburst plots out there.

Clearly reproducing this issue isn’t a problem tho

@nicolaskruchten I believe I was able to reproduce the behavior described. I’m using Plotly in a Python/JupyterLab environment. If I use the Eve sunburst example in a notebook cell with the branchvalues attribute removed, I get the following:

If I then add the branchvalues=True attribute, I will get a blank plot output. As shown below:

I took a look at the browser console during both cell executions and got two plotly.js errors when the blank plot was created. Below are the errors:

plotly.js:25536 Error: attribute d: Expected number, “MNaN,NaNLNaN,NaNA…”.
plotly.js:25529 Error: attribute transform: Expected number, “translate(NaN,NaN)translat…”.

BTW and forgot to mention in my first post, this happens on both Plotly v4.1.0 and V4.3.0.

Thanks very much @kev.mock! I’m unable to replicate this locally in either JupyterLab or classic Notebooks, which is pretty strange! The same code also works in straight plotly.js in a CodePen, so there’s something else going on here.

Ah I think I know what’s happening here. This happens with Plotly.js version 1.49.4, which shipped with Plotly.py 4.1.0. It’s possible you would still see this in Plotly.py 4.3.0 in JupyterLab if you haven’t updated your labextensions … Please check out our Getting Started guide for installation instructions for the JupyterLab extensions, which must be upgraded alongside the plotly module in order to get access to the latest features and bugfixes.

@nicolaskruchten Yep you are correct. I updated to 4.3.0 of Plotly but didn’t update the lab extension. After the labextension update, the plots are working normally. Thanks for the help!

Hi,

Can you tell me why does the Chart Studio Sunburst need Parents and ID data to be combined (hyphenated) data fields? This is not a requirement of plotly.express

I get a plotly.express sunburst without using combined fields; and yet chart studio does not create the plot when I use data that works with plotly.express

Plotly Express accepts -

fig = px.sunburst(df2, path=[‘topic’,‘subtopic1’,‘desc’], values=‘score’, maxdepth=2, hover_data = [‘code’], hover_name = “http://csq1.org/info/” + df2[‘code’]+".htm")
fig.show()

Here is what Chart Studio works with:

Hi Nicolas,
I have a large set of data. In the data set a label (or a name) could be assigned to different parents. This will cause issues as explained (empty plot space). In real world it is possible to have one name assigned to many parents. If I want to change the labels in 23000 records with eight levels in hierarchy, it would be really cumbersome. Is there any solution for this issue in Plotly? A simple reproducing of the issue is as follows (ID assigned to two different parents):

import plotly.graph_objects as go
go.Figure(
go.Sunburst(
labels = [“Seth”, “Enos”, “Noam”, “Awan”, “Enoch”,‘ID’,‘ID’],
parents = ["", “Seth”, “Seth”, “”, “Awan”,‘Seth’,‘Awan’],
values = [12, 10, 2, 4, 4,2,5],
branchvalues=“remainder”
)
)

@Vahid.E you can definitely have reused labels, but in that can you must set a unique id to each datum, and parents must refer to ids… See this documentation example for details on repeated labels: https://plotly.com/python/sunburst-charts/#sunburst-with-repeated-labels

Hi @nicolaskruchten, I seem to have a similar issue. I can generate a chart in the browser on its own without issue:

    fig = px.sunburst(dff, path=['Fixed/Floating ', 'FIT/ROC', 'counterparty_vendor', 'gc_portfolio',
                                          'Plant ID'], values='capacity_dc', color='Fixed/Floating ',
                                           color_discrete_map={'(?)': '#e4e6df', 'Fixed': '#8cab2e',
                                                               'Floating': '#4d83b3'})
    fig.update_layout(height=800, margin={'t': 50, 'b': 10, 'l': 10, 'r': 10})
    fig.show(renderer='browser')

but when I embed it in a dash page I get the following errors:

Error: attribute transform: Expected number, “translate(NaN,NaN)scale(0.…”.
Error: attribute d: Expected number, “MNaN,NaNLNaN,NaNA…”.

Any ideas?

Many thanks in advance!

@jlperez can you confirm you’re running a recent version of plotly (and, if in JupyterLab, the jupyterlab-plotly extension)? We released 4.9.0 yesterday.

@nicolaskruchten, I’m running 4.8.1. Running from PyCharm locally and production in Azure - same error. Thanks!

@nicolaskruchten, the upgrade did the trick. Thanks a lot!