gpt4 book ai didi

python - Bokeh 和 Networkx - 悬停工具提示显示多个箭头

转载 作者:太空宇宙 更新时间:2023-11-04 04:15:17 26 4
gpt4 key购买 nike

我一直在尝试使用以下代码在 Bokeh 中可视化 networkx 网络...

import networkx as nx
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from bokeh.plotting import figure, ColumnDataSource
from bokeh.models.sources import CDSView
from bokeh.io import show, output_notebook
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, BoxZoomTool, ResetTool
from bokeh.models.graphs import from_networkx, NodesAndLinkedEdges, EdgesAndLinkedNodes, NodesOnly
from bokeh.palettes import *

V = [1,2,3,4,5,6]
E = [(1,2), (4,5), (2,3)]

G=nx.Graph()
G.add_nodes_from(V)
G.add_edges_from(E)

plot = figure(plot_width=500, plot_height=500,
x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1))
plot.title.text = "Networkx/Bokeh Example"
plot.axis.visible = None
plot.background_fill_color = "white"
plot.grid.grid_line_color = None

network_src = dict()
network_src['index'] = V
network_src['name'] = ['one', 'two', 'three', 'four', 'five', 'six']
network_src['size'] = [15,15,15,30,15,30]
network_src['node_cols'] = ['#2b83ba','#2b83ba','#2b83ba','#abdda4','#abdda4','#fdae61']
network_src = ColumnDataSource(network_src)

graph_renderer = from_networkx(G, nx.spring_layout, scale=1, center=(0, 0))
graph_renderer.node_renderer.glyph = Circle(size='size', fill_color='node_cols')
graph_renderer.node_renderer.data_source = network_src
graph_renderer.node_renderer.view = CDSView(source=network_src)

node_hover_tool = HoverTool(tooltips=[("Name", "@name")])

plot.add_tools(node_hover_tool)

plot.renderers.append(graph_renderer)

output_notebook()
show(plot)

这很好用,但是当我将鼠标悬停在某些节点上时,它会在框周围显示多个箭头。我读到这是因为它试图将悬停工具提示分配给边缘和节点渲染器......但我已经尝试修复它并且似乎无法找到正确的解决方案。请帮忙!谢谢。

最佳答案

看起来像一个错误。请举报here .现在你可以使用:

node_hover_tool = HoverTool(tooltips = [("Name", "@name")], show_arrow = False)

关于python - Bokeh 和 Networkx - 悬停工具提示显示多个箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55572683/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com