0

I would like to label the connecting string in a sankey label.

I have generated a sample figure with the code below, and I'd like to add automatically the labels I added by hand. I tried to set "label" as in documentation, but it seems it made no difference.

        label
            The shown name of the link.

Thank you

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

df = pd.DataFrame()

df['label'] = [ 
    ''.join(
            random.choices(
                string.ascii_letters + string.digits, k=4))
    for _ in range(10) ]
df['in'] = np.random.randint(1, 6, 10)
df['out'] = np.random.randint(1, 6, 10)
df['weights'] = np.random.uniform(1, 6, 10)
df['x.pos'] = [ random.choice([0.1, 0.5, 0.9]) for _ in range(10) ]
df['connect'] = [ random.choice(string.ascii_letters) for _ in range(10) ]

fig = go.Figure(data=[go.Sankey(
    arrangement = "snap",
    node = {"label": df['label'],
            "x" : df['x.pos'] },
    link = {"source": df['in'],
            "target": df['out'],
            "value" : df['weights'],
            "label" : df['connect']}
    )])

enter image description here

Derek O
  • 16,770
  • 4
  • 24
  • 43
Marco Di Gennaro
  • 395
  • 1
  • 3
  • 15
  • 3
    Unfortunately the link labels are only shown on hover, see this [feature request](https://github.com/plotly/plotly.js/issues/4746) for updates. – EricLavault Feb 16 '23 at 13:41

0 Answers0