Line breaks for sankey labels

Hello! I have long labels for my sankey nodes, and I’d like to break the content down to two lines:

What I have now:
ā€˜example label for sankey node’

What I want:
ā€˜example label
for sankey node’

Does anyone know if this is possible? I have tried a whole manner of packages and workarounds (
\n textwrap) etc. and nothing seems to work. Thanks in advance!

Add ā€œ<br>ā€ between the strings for each value. For example:

ā€œexample label for Sankey nodeā€ -> ā€œexample label <br> for Sankey nodeā€.

If you have your data in a df, then something like:
df[ā€˜label’] = df[ā€˜pt1’] + ā€˜<br>’ + df[ā€˜pt2’]

Hi louis,

Thanks for the input – unfortunately, I already tried that option and it doesn’t work. < br > just shows up as part of the text. I wonder if it’s specific to the internal formatting of sankey labels…

I don’t know whether it makes a difference, but I’m also using f strings as part of the string I’d like to break into two lines.

You mind sharing your code?

Sure, here’s what I’m working with:

node = dict(
label = [f’BAU Coal: {round(future_em_list[0]+avoided_em_list[0],2)}MMt CO2eq’]

I want ā€˜BAU Coal:’ to be on one line and the rest to appear below.

So I tried a bunch of stuff, and it seems as tho the hover label does in fact work with the
added in, but the labels themselves don’t.
48%20PM

After some digging it seems like this is an issue that has been created:

https://github.com/plotly/plotly.py/issues/1499

Looks like it’s an issue on their side. I would recommend you add a shortened label and ad the full label on the hover (even though not ideal).

Thanks a bunch; that’s what I’ll do!