Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To adjust the alignment of nodes along the x-axis in a Plotly Sankey diagram, you can specify the location of each node using its x-coordinate. The x-coordinate of each node can be set in the node definition using the x attribute. For example, if you have a node with the name "A" and you want it to be located at x=1, you can define it as follows:

trace = go.Sankey(
    node = dict(
        label = ["A"],
        x = [1]
    ),
    # rest of the Sankey trace definition
)

To control the drop-off in the Sankey diagram, you can adjust the node.pad and node.thickness attributes. The node.pad attribute controls the amount of vertical space between each node, while the node.thickness attribute controls the width of each node. Increasing node.pad will decrease the drop-off between nodes, while decreasing node.thickness will increase the drop-off.

trace = go.Sankey(
    node = dict(
        pad = 25, # increase the node padding
        thickness = 20 # decrease the node thickness
    ),
    # rest of the Sankey trace definition
)

You may also want to adjust the arrangement attribute to control the orientation of the Sankey diagram. If you set arrangement = "snap", the nodes will be aligned along the x-axis, but may also affect the drop-off between nodes.

trace = go.Sankey(
    node = dict(
        label = ["A", "B", "C"],
        x = [0, 0.5, 1],
        pad = 25,
        thickness = 20
    ),
    link = dict(
        source = [0, 0, 1],
        target = [1, 2, 2],
        value = [10, 5, 5]
    ),
    arrangement = "snap" # arrange the nodes along the x-axis
)