4
US_TOTAL_REVENUE = 50
INTERNATIONAL_TOTAL_REVENUE = 50
REVENUE = 100
GROSS_PROFIT = 10
COST_OF_REVENUE = 110

We have a business that operates on a loss. Their COST_OF_REVENUE (110) is higher than their REVENUE (100) resulting in a GROSS_PROFIT / LOSS of 10.

import pandas as pd
import numpy as np
import plotly.graph_objects as go

source = [0, 1, 2, 2,]
target = [2, 2, 3, 4,]
value = [US_TOTAL_REVENUE, INTERNATIONAL_TOTAL_REVENUE, GROSS_PROFIT, COST_OF_REVENUE]
label = [f'US_TOTAL_REVENUE {value[0]}', f'INTERNATIONAL_TOTAL_REVENUE {value[1]}', f'REVENUE {REVENUE}',
         f'GROSS_PROFIT {value[2]}',f'COST_OF_REVENUE {value[3]}']
d = {'source': source, 'target': target, 'value':value}#, 'label':label}
df = pd.DataFrame(data=d)
nodes = np.unique(df[["source", "target"]], axis=None)
nodes = pd.Series(index=nodes, data=range(len(nodes)))

fig = go.Figure(
    go.Sankey(
        arrangement="snap",
        node={"label": label, "pad" : 20},
        link={"source": source, "target": target, "value": value},
    )
)
fig.show()

If I use a negative value for GROSS_PROFIT no link will be shown. If I use a positive value it will result in the following graphic.

Wrong Sankey Plot

I do not want to change the COST_OF_REVENUE value because it will be split up into multiple other links and nodes (not shoen in the graphic), so the wrong value would propagate into other layers.

Is there an algorithm or a visualization technique for negative values in sankey diagrams?

BigBen
  • 46,229
  • 7
  • 24
  • 40

0 Answers0