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

标签 python matplotlib tooltip bokeh networkx

我一直在尝试使用以下代码在 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/

相关文章:

python - 如何在 Python3 中使用 pylab 去除 x 轴标签中的困惑/重叠?

python - 将图例添加到散点图 (PCA)

angularjs - 仅当文本在 angular UI bootstrap 指令中被截断时才显示工具提示

javascript - Highcharts 位置工具提示在堆叠条的中间

jquery - 在 qtip 上方显示 jQueryUI 工具提示

python - 如何在 python 3.7 中使用正则表达式来拥有 2 或 3 个组?

python - 有没有一种方法可以在不使用 python GIL 的情况下进行序列化/反序列化

python - Pandas 条形图没有显示我需要的东西

python - LaTeX 与 Python 3.7 和 Matplotlib

python - 对新列中的数据进行分类