0

I am using a python dataframe to collect data required for my Holoviews Sankey before creating the graph. I need specific labels for the nodes. The below works fine (as long as the number of edges >= number of nodes)

import pandas as pd

import holoviews as hv

from holoviews import opts, dim

hv.extension('bokeh')

data={'Start':['A','A','B','B'],'End':['X','Y','X','Y'],'Size':[3, 10, 6, 1],'Label': ['myA','myB','myX','myY']}

dfTesting=pd.DataFrame(data)

sankey = hv.Sankey(dfTesting).opts(show_values=False, labels=dim('Label'))

sankey.opts(width=600, height=400)

Sankey Graph created

However, if the edges < number of nodes, this will not work. Can you pls help on how to fix this? I need to use bokeh as I need the features in it and need custom labels as these are created dynamically based on user inputs. The below code gives as error as the plot is looking for the third label. Thank you.

data={'Start':['A','A'],'End':['X','Y'],'Size':[3, 10],'Label':['myA','myX']}  # no 'myY'

dfTesting=pd.DataFrame(data)

sankey = hv.Sankey(dfTesting).opts(show_values=False, labels=dim('Label'))

sankey.opts(width=600, height=400)

**ERROR ** - IndexError: index 2 is out of bounds for axis 0 with size 2

Redox
  • 9,321
  • 5
  • 9
  • 26
  • I can not reproduce your error. The second example works on my machine without an error. – mosc9575 Mar 28 '22 at 19:03
  • Thanks @mosc9575 for your response. Appreciate it. Are you sure it was the second example worked? There are only two 'Labels' provided (myA, myX) through the dataframe, while there are 3 nodes(A, B, X). Did you add another row? Can you pls let me know what versions you used or if you made any changes to code/data? I am using python 3.8.5 on windows, holoviews 1.14.8 and Jupyter-notebook 6.1.4 – Redox Mar 29 '22 at 03:55
  • I was able to fix issue by adding another row to 'data' table. IMPORTANT: new row should have source & destination nodes that is already in the data (source-A and dest.-X in my case) and the edge of size=0. 'data = {'Start': ['A', 'A', 'A'],'End':['X', 'Y', 'X'],'Size': [3, 10, 0],'Label': ['myA', 'myX', 'myY']}' – Redox Apr 05 '22 at 11:02

0 Answers0