Node and link sizes not matching in a Plotly Sankey Diagram

Hi all!

I am learning Python plotting with Plotly Sankey Diagram and I am trying to plot income statements of stocks.

I am unable to figure out why the node and link sizes have a discrepancy at some of the nodes. For example, Income before tax (value=2B) going into Income Tax (value=417M) and Net Income - Cont. Ops (value=1.58B)

Here is the code:

fig = go.Figure(data=[go.Sankey(
node = dict(
pad = 30,
thickness = 20,
line = dict(color = “white”, width =0),
label = [f"Total Revenue {fmt_df.at[0,'totalRevenue']}", #0 f"Gross Profit {fmt_df.at[0,‘grossProfit’]}“, #1
f"Cost of Revenue -{fmt_df.at[0,'costOfRevenue']}", #2 f"SG&A -{fmt_df.at[0,‘sellingGeneralAdministrative’]}”, #3
f"R&D -{fmt_df.at[0,'researchDevelopment']}", #4 f"Other -{fmt_df.at[0,‘otherOperatingExpenses’]}“, #5
f"Operating Income {fmt_df.at[0,'operatingIncome']}", #6 f"Income Before Tax {fmt_df.at[0,‘incomeBeforeTax’]}”, #7
f"Other Income Expenses {fmt_df.at[0,'totalOtherIncomeExpenseNet']}", #8 f"Income Tax {fmt_df.at[0,‘incomeTaxExpense’]}“, #9
f"Net Income - Cont Ops {fmt_df.at[0,'netIncomeFromContinuingOps']}", #10 f"Discontinued Operations {fmt_df.at[0,‘discontinuedOperations’]}”, #11
f"Net Income ${fmt_df.at[0,‘netIncome’]}" #12
],
color = [‘#519E3F’,‘#519E3F’,‘#BC271B’,‘#BC271B’,‘#BC271B’,‘#BC271B’,‘#519E3F’,‘#519E3F’,‘#BC271B’,‘#BC271B’,‘#519E3F’,‘#519E3F’,‘#519E3F’]
),
textfont=dict(family=‘sans serif’,size=20,
color=‘rgba(0,0,0,1)’),
link = dict(
source = sources,
target = targets,
value = values,
color = link_colors
))])
fig.show()

sources = [0,0,1,1,1,6,6,7,7,10,11]
targets = [1,2,6,3,4,7,8,10,9,12,12]
values = [raw_df.loc[0,‘totalRevenue’],raw_df.loc[0,‘grossProfit’],raw_df.loc[0,‘costOfRevenue’],raw_df.loc[0,‘sellingGeneralAdministrative’],
raw_df.loc[0,‘researchDevelopment’],raw_df.loc[0,‘operatingIncome’],raw_df.loc[0,‘incomeBeforeTax’],abs(raw_df.loc[0,‘totalOtherIncomeExpenseNet’]),
raw_df.loc[0,‘incomeTaxExpense’],raw_df.loc[0,‘netIncomeFromContinuingOps’],raw_df.loc[0,‘netIncome’],raw_df.loc[0,‘discontinuedOperations’]]
link_colors=[‘#A4CC9E’,‘#D58A87’,‘#A4CC9E’,‘#D58A87’,‘#D58A87’,‘#A4CC9E’,‘#D58A87’,‘#A4CC9E’,‘#D58A87’,‘#A4CC9E’,‘#A4CC9E’] #Colors Green:‘#A4CC9E’,Red: ‘#D58A87’

Json format raw_df table:

[{“index”:0,“endDate”:1688083200,“totalRevenue”:15475000000,“costOfRevenue”:6974000000,“grossProfit”:8501000000,“researchDevelopment”:1687000000,“sellingGeneralAdministrative”:4900000000,“nonRecurring”:null,“otherOperatingExpenses”:-248000000,“totalOperatingExpenses”:13313000000,“operatingIncome”:2162000000,“totalOtherIncomeExpenseNet”:-162000000,“ebit”:2162000000,“interestExpense”:-423000000,“incomeBeforeTax”:2000000000,“incomeTaxExpense”:419000000,“minorityInterest”:70000000,“netIncomeFromContinuingOps”:1581000000,“discontinuedOperations”:2000000,“extraordinaryItems”:null,“effectOfAccountingCharges”:null},{“index”:1,“endDate”:1680220800,“totalRevenue”:14251000000,“costOfRevenue”:6743000000,“grossProfit”:7508000000,“researchDevelopment”:1655000000,“sellingGeneralAdministrative”:4858000000,“nonRecurring”:null,“otherOperatingExpenses”:-180000000,“totalOperatingExpenses”:13076000000,“operatingIncome”:1175000000,“totalOtherIncomeExpenseNet”:-117000000,“ebit”:1175000000,“interestExpense”:-367000000,“incomeBeforeTax”:1058000000,“incomeTaxExpense”:124000000,“minorityInterest”:68000000,“netIncomeFromContinuingOps”:934000000,“discontinuedOperations”:-7000000,“extraordinaryItems”:null,“effectOfAccountingCharges”:null},{“index”:2,“endDate”:1672444800,“totalRevenue”:16690000000,“costOfRevenue”:7058000000,“grossProfit”:9632000000,“researchDevelopment”:1604000000,“sellingGeneralAdministrative”:4847000000,“nonRecurring”:null,“otherOperatingExpenses”:-232000000,“totalOperatingExpenses”:13277000000,“operatingIncome”:3413000000,“totalOtherIncomeExpenseNet”:-100000000,“ebit”:3413000000,“interestExpense”:-313000000,“incomeBeforeTax”:3313000000,“incomeTaxExpense”:444000000,“minorityInterest”:77000000,“netIncomeFromContinuingOps”:2869000000,“discontinuedOperations”:-159000000,“extraordinaryItems”:null,“effectOfAccountingCharges”:null},{“index”:3,“endDate”:1664496000,“totalRevenue”:14107000000,“costOfRevenue”:6677000000,“grossProfit”:7430000000,“researchDevelopment”:1611000000,“sellingGeneralAdministrative”:4545000000,“nonRecurring”:null,“otherOperatingExpenses”:-120000000,“totalOperatingExpenses”:12713000000,“operatingIncome”:1394000000,“totalOtherIncomeExpenseNet”:-5895000000,“ebit”:1394000000,“interestExpense”:-295000000,“incomeBeforeTax”:-4501000000,“incomeTaxExpense”:-1287000000,“minorityInterest”:71000000,“netIncomeFromContinuingOps”:-3214000000,“discontinuedOperations”:18000000,“extraordinaryItems”:null,“effectOfAccountingCharges”:null}]

Image of the plot (rearranged manually):

Any ideas or suggestions?