Visualize stock flow using plotly sankey

19 Views Asked by At

I want to visualize how stock (items delivered on a certain day to a store) is subsequently sold (same-day or future days). I thought of doing this using a Sankey diagram. This seems to work. I've put the stock on the left and the sales on the right. However, what I do not like is that the dates overlap.

This should work for many more "transactions" than in this simple example:

fig = go.Figure(
    data=[
        go.Sankey(
            arrangement="snap",
            node=dict(
                pad=15,
                thickness=20,
                line=dict(color="black", width=0.5),
                label=[
                    "01/01 - stock",
                    "01/02 - stock",
                    "01/01 - sales",
                    "02/02 - sales",
                    "03/02 - sales",
                ],
                color="blue",
                x=[0.0, 0.0, 1.0, 1.0, 1.0],  # x positions
                y=[0.0, 0.1, 0.0, 0.1, 0.2],  # y positions
            ),
            link=dict(
                source=[
                    0,
                    0,
                    1,
                    1,
                ],
                target=[2, 3, 3, 4],
                value=[1, 0.5, 2, 1],
            ),
        )
    ]
)
fig.show() 

This gives:

enter image description here

What I want is more like this:

enter image description here

So, the stock and sales node should start at the same height, and a future sales date should not overlap vertically with a sales date in the past.

How can I achieve this?

0

There are 0 best solutions below