How can fixed scales be set in sankey python plots

I’m trying to produce Sankey plots that have the same scale as each other.
Any help would be greatly appreciated.

Hi @span, I am still confused by what you mean by β€˜Sankey plots that have the same scale as each other’ Do you mean the output size of the Sankey? e.g. 1024px X 768px? which you can specify in Plotlt graph objects

# Update chart with some customisations

Can you share what you have or mock up some data that shows your issue and then we can get you to where you need to be?



Hi Tom,

Thank you so much for getting back to me.

I want to be able to compare two sankeys, so that the number of pixels is fixed to the unit being represented.

X pixels / unit across different sankeys. Is that possible?


The orange and blue parts of the second should add up to the orange in the first in terms of space taken up (y-axis)

Does that make sense, or do I need to put some code together?

Best regards and thank you for your help,



Hi Anna,

Sorry for the late reply. I looked into the documentation around this and I do not believe there is a way to specify the pixels/unit that you talk about. The only real control you have over the size is with the size of the chart itself specifying its height and width.

I might be wrong. perhaps @adamschroeder or @AnnMarieW may be able to shed some insights on this?

Hey @span, welcome to the forums.

If I understood your question correctly, the only way to achieve this, is setting the pad parameter to 0.

import plotly.graph_objects as go

s1 = go.Sankey(
    node = dict(
        pad = 0,
        # ^^ this defines the distance between the nodes. 
        thickness = 15,
        line = dict(color = "black", width = 0.5),
        label = ["A1", "A2", "B1"],
        color = "blue"
    link = dict(
        source = [0, 1],
        target = [2, 2],
        value = [8, 4],
        color = ['red', 'gray']
    domain={'x': [0.0, 0.45]}
    # show on the left half of the figure

s2 = go.Sankey(
    node = dict(
        thickness = 15,
        line = dict(color = "black", width = 0.5),
        label = ["A1", "B1"],
        color = "blue"
    link = dict(
        source = [0],
        target = [1],
        value = [12],
        color = ['red']
    domain={'x': [0.55, 1.0]}
    # show on the right half of the figure

# create figure
fig = go.Figure(data=[s1, s2])

# create some visual reference

# hide axes

Here an image with pad=15

1 Like


Thanks for the information, I will try it out.

And let you know if it works






1 Like

I tried it, but unfortunately for my data i bring in an extra source and then that shrinks the sources & targets to fit the page or figure

The purple node on the far right has the same value in both diagrams but gets squeezed to make space for the green (which is coming from the blue).
Thanks anyway for thinking about my problem.