1

就像标题所说的那样,我使用了从多个地方收集的一些代码来构建这个和弦图,但不幸的是,最后一件会阻碍 100% 完美的事情是这个弹出窗口,每当我将鼠标悬停在标签。即使鼠标移动到其他地方,弹出窗口仍然存在......顺便说一句,我正在使用 Python 和 Holoviews 来绘制和弦。我很确定这是由于错误或其他原因造成的……但是,我很想找到一种绕过它的方法……此处示例:错误示例

代码 :

%%opts Chord [height=600 width=600 title="Transactions from 2000 to 2021" ]
#plot 
#edit links = moves[moves['Transactions'] > x] // x refers to the number of transactions minimum for the diagram display
moves = moves[moves['Transactions']>5]
links = moves
chord = hv.Chord(links)
chord
nodesl = []
c = []
for i, row in moves.iterrows():
    c.append(row[0])
    c.append(row[1])

c = pd.DataFrame(c)
c.drop_duplicates(inplace=True)
c.reset_index(inplace=True)
c.drop(columns='index', inplace=True)
c 

nodes = []
for i, row in c.iterrows():
    nodes.append({'name':row[0]})


nodes = pd.DataFrame(nodes)
# nodes

nodes = hv.Dataset(nodes, 'name')
nodes.data.head()



%%opts Chord [height=800 width=800  bgcolor="black"]
%%opts Chord [title="Transactions from 2000 to 2021 (Countries with over 5 moves)\nTip: Please do not hover over the label as it might produce a bug, else refresh the page" ]

chord = hv.Chord((links, nodes)).select(value=(5, None))

#this function allows text to fit perfectly on the screen
def rotate_label(plot, element):
    text_cds = plot.handles['text_1_source']
    length = len(text_cds.data['angle'])
    text_cds.data['angle'] = [0]*length
    xs = text_cds.data['x']
    text = np.array(text_cds.data['text'])
    xs[xs<0] -= np.array([len(t)*0.019 for t in text[xs<0]])

chord.opts(
    opts.Chord(cmap='Category10', 
               edge_color=dim('Target').str(), 
               node_color=dim('name').str(),
               labels='name',
               label_text_color="white",
               hooks=[rotate_label]
               ))
chord
4

1 回答 1

1

???通常表示它试图显示的某些字段不可用;不知道为什么会在这种情况下。您始终可以通过设置覆盖HoloViews用于 Bokeh 的默认工具default_tools=[],然后指定您想要的任何工具,无需.'hover'tools=['save', 'pan', 'wheel_zoom', 'box_zoom', 'reset']

于 2021-10-24T14:38:51.773 回答