Search code examples
plotlysankey-diagram

Plotly Sankey node X Position isn't as expected


I have a plotly sankey diagram which I'm trying to manually position the nodes.

The node definition look like this :

"node" = {
"labels": ["undefined", "undefined category", "utilities", "Asking for information", "transport and highways", "reporting an issue", "street cleaning", "escalated", "Handled by Knowledge", "handled by triage"],
"x": [0.0001, 0.5, 0.0001, 0.5, 0.0001, 0.5, 0.0001, 0.9999, 0.9999, 0.9999]
}

I've written it as JSON, however my configuration is actually generated from C# since I'm using the Blazor.Plotly nuget lib.

I've excluded the Y array for brevity.

So... looking at the configuration I would, for example, expect the node with label "Utilities" to have an X position of 0.0001 and yet it's displayed in the center of the screen (horizontally)!

I suspect I misunderstand how the X and Y arrays are supposed to be arranged!

Any ideas?

enter image description here


Solution

  • So... the issue for me in this case was that the label "undefined category" wasn't a target for any source node (my chart was being generated dynamically).

    This meant that while the nodes definitions (labels, x and y) were grand, and links looked sensible, there was a node that wasn't referenced by links!

    So, if your nodes aren't where you expect them to be and the X/Y positions align as expected to the labels, make sure all your labels are referenced!