0

我用 HoloViews 创建了一个和弦图。我正在尝试在弧上设置悬停工具提示,希望也可以在我的和弦图的节点上。但是,我不知道如何应用正确的语法。所有尝试都以 ?? 在工具提示中:

在此处输入图像描述

我的数据框包含三列,“源”、“目标”和值。数据框的片段如下所示:

            source           target  value
0            khaki            khaki     21
1            khaki  mediumslateblue     22
2            khaki       lightgreen     15
3            khaki       lightcoral     13
4  mediumslateblue            khaki     23

完整的代码可以在这里找到:

import pandas as pd
import numpy as np
from holoviews import opts, dim
import holoviews as hv
from bokeh.models import HoverTool
from bokeh.plotting import ColumnDataSource, figure, output_file, show


hv.extension('bokeh')
hv.output(size=200)

my_dict = {'khaki': {'khaki': 21, 'mediumslateblue': 22, 'lightgreen': 15, 'lightcoral': 13}, 'mediumslateblue': {'khaki': 23, 'mediumslateblue': 13, 'lightgreen': 4, 'lightcoral': 21}, 'lightgreen': {'khaki': 23, 'mediumslateblue': 16, 'lightgreen': 10, 'lightcoral': 9}, 'lightcoral': {'khaki': 4, 'mediumslateblue': 10, 'lightgreen': 29, 'lightcoral': 9}}
color_dict = {'Color': {0: '(252, 255, 104)', 1: '(104, 107, 255)', 2: '(104, 255, 119)', 3: '(255, 104, 129)'}, 'ColorName': {0: 'khaki', 1: 'mediumslateblue', 2: 'lightgreen', 3: 'lightcoral'}}

df = pd.DataFrame(my_dict)
df_colors = pd.DataFrame(color_dict)

data = hv.Dataset((list(df.columns), list(df.index), df),['source', 'target'], 'value').dframe()
print(data.head())
TOOLTIPS = [
    ("index", "$index"),
    ("Source", "@source"),
    ("Target", "@target"),
    ("Value", "@value"),
]

hover = HoverTool(tooltips=TOOLTIPS)
chord=hv.Chord(data)

chord.opts(
    opts.Chord(tools=[hover],cmap='Category20', edge_cmap='Category20', edge_color=dim('source').str(), 
                label_index='index', node_color=dim('index').str()))

我的问题与此类似。但是,我不想摆脱弹出窗口,而是想用相关信息填充工具提示;将鼠标悬停在和弦图中的标签上时如何摆脱此弹出窗口(Holoviews - Python)

任何帮助表示赞赏!

4

0 回答 0