Python 基于Bokeh和Holoviews群的弦图着色

Python 基于Bokeh和Holoviews群的弦图着色,python,bokeh,holoviews,Python,Bokeh,Holoviews,全部。 我的电脑有点问题。 我有两个pd数据帧,其中一个定义了我想在弦图中看到的所有连接: conns = pd.DataFrame(links) print(conns) from to value parent 0 01.110 01.120 1 A 1 01.110 01.130 1 A 2 01.110 01.190 1 A 3 01.110 01.260

全部。 我的电脑有点问题。 我有两个
pd数据帧
,其中一个定义了我想在弦图中看到的所有连接:

conns = pd.DataFrame(links)
print(conns)


        from      to  value parent
0     01.110  01.120      1      A
1     01.110  01.130      1      A
2     01.110  01.190      1      A
3     01.110  01.260      1      A
4     01.130  01.190      1      A
...      ...     ...    ...    ...
1319  96.090  88.910      1      S
1320  96.090  90.010      1      S
1321  96.090  93.190      1      S
1322  96.090  96.010      1      S
1323  99.000  84.210      1      U
如果我用 hv.Chord(康涅狄格州),我得到以下曲线图:

这正是我想要的,但是,我想根据“父对象”添加颜色,如果可能的话,将父对象值添加到工具提示中。我一直在为此绞尽脑汁,结果如下:

代码:

但是,在
opts
中添加参数
node_color=dim('parent').astype(str))
会引发一个错误:
ValueError:应该是字符串、Dict(Enum('expr','field','value','transform')、字符串、实例(transform)、实例(表达式)、颜色)或颜色(got dim('parent').astype(dtype=)

据我所知,应该使用
hv.Dataset
对象,我是这样构造的,但我不知道如何将其传递给hv.Chord()

hv.Chord(conns, ['from', 'to'], ['value', 'parent']).opts(
opts.Chord(cmap='Category20', edge_color=dim('parent').astype(str)))
nn_d = nn_d[['index', 'parent']]
nodes = hv.Dataset(nn_d, ['index'], ['parent'])
print(nn_d)


        index parent
0      01.110      A
1      01.130      A
2      01.140      A
3      01.150      A
4      01.190      A
...       ...    ...
10159  96.022      S
10160  96.030      S
10161  96.040      S
10162  96.090      S
10163  99.000      U