当节点超过边缘时未设置的holoviews sankey图标签

发布于 2025-01-17 11:20:24 字数 1004 浏览 1 评论 0原文

在创建图表之前,我使用 python 数据框来收集 Holoviews Sankey 所需的数据。我需要节点的特定标签。下面的代码工作正常(只要边数 >= 节点数

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)

桑基图已创建

但是,如果边 <节点数量,这将不起作用。您能帮忙解决这个问题吗?我需要使用散景,因为我需要其中的功能,并且需要自定义标签,因为这些标签是根据用户输入动态创建的。下面的代码给出了错误,因为绘图正在寻找第三个标签。谢谢。

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)

**错误 ** - IndexError:索引 2 超出尺寸 2 的轴 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文