✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

Sunburst branchvalues parameter

I’m struggling to use the sunburst graph object in a Jupyter notebook. It’s perfect for my use case (spread of file formats in a given corpus), however using the parameter branchvalues=‘total’ gives me just a white box.
A dodgy workaround setting the parent values to 0 gives me this:

which is how it should look. I’ve rechecked my data several times, the combined value of children adds up foreach parent.

trace = go.Sunburst(
    outsidetextfont = {"size": 20, "color": "#377eb8"},
    marker = {"line": {"width": 2}},
layout = go.Layout(
    margin = go.layout.Margin(t=0, l=0, r=0, b=0, )
iplot(go.Figure([trace], layout), filename='format_spread')
1 Like

I’m having this same issue, all of the value add up to their parents and so on! were you able to solve this? I would greatly appreciate any help

The only thing I can think of is that my values are floats and that’s making an issue

The idea behind branchvalues is that for a sunburst like the one above, you either externally calculate the values for every sector and use total OR you specify the value of all leaves and set the branch values to 0 and use remainder.

The more interesting case is if you ever have a parent whose width is not fully accounted for by its children. In this case you either specify the total value of the parent or the “remainder” value of the parent i.e. the additional width of the parent, over and above that of the children.

Hope that helps!

Unfortunately I was never able to rectify it, I checked repeatedly the values of parents and children and could not work out where the issue was. My values are integers, so using floats is probably not your issue.

Hi Nicholas,

For the above plot, the values for each parent were calculated externally and the children values added to the total of each parent, hence my confusion. Setting branch values to 0 is a poor solution as I’d like to know the totals for branch and leaf values.

Ah I see. I would love to see an example of this with numbers so I can track it down! It definitely seems like a bug with total mode.

For remainder mode, when you say you want to “know” the values, do you mean when you hover over the sectors? This is possible via hovertemplate I believe, if not in 1.49.x, in the 1.50.x version of plotly.js which was just released, and should be available in the soon-to-come plotly.py 4.2 :slight_smile:

For example, this works as expected:

import plotly.graph_objects as go

    labels=["a", "b", "c", "d"],

I’d share the data with you, but I removed the figure as I just couldn’t get it to work! Their is potentially something I’m missing, but I can’t see it. If I have a chance I’ll try and recreate it, as it is a very neat way of visualising these sort of stats.
Yes the hover worked, but if I have to set branch values to , then of course this is not an accurate figure.

Capture1 Capture2 Capture

Pic 1 is what the sunburst looks like, pic 2 is how I would like it to look.

This is the data that I’m using, I’ve manually added up all the values and they add up exactly to the value of their parent. I’ve also tried the workaround mentioned above by setting the root value to zero.

I don’t understand why the visualization will only work with branchvalues = remainder.
I have made a smaller dummy data to test to plot a sunburst with branchvalues=total (the 2nd picture) and that works fine

Have you found a solution to this problem? I am having a similar issue. I want the wedges to be evenly distributed with respect to the size of the parent. When using branchvalues=‘total’ on a small test dataset this works perfectly. But when I use large dataset I get a blank plot.

1 Like

This seems like a bug, so any help in reproducing it would go a long way towards a fix :slight_smile:

No I haven’t unfortunately! at least I know it’s not just me. Mine also worked on a smaller dataset, I don’t understand the issue as mine isn’t a particularly large plot it only has two layers.

By any chance did you also have repetitive labels on any of the layers?

Could you be more specific as to exactly what you would like to see? I’ve already shared the data I’m using, any attempt to plot a bare simple sunburst it with branchvalues =totals fails

To reproduce the bug I would need the data in copy-pasteable text form rather than as a screenshot, actually :slight_smile:

Also, I wonder if the duplicate IDs in your data might be causing a problem…

I believe all ids are unique? the above data is created within an R script that pulls data from different sources, I will save it to excel and try to share it on here

meanwhile there is another post here, with the data, encountering the same issue: Plotly Sunburst returning empty chart with branchvalues = 'total'

I have loads of duplicate labels throughout the layers and I use the ids array to overcome that. I actually figured out a work around for my particular problem. I use remainder instead of total and set the weights in the values array. I wanted the wedges to be symmetrical on all layers and for the wedges to take up the entire circle. However, because my data set is very large (about 18,000 nodes) there was a lot of math, graph theory and headaches involved in my solution.

@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: