Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法在Bokeh中使用鼠标悬停工具显示NetworkX中的标签_Python_Graph_Bokeh_Networkx - Fatal编程技术网

Python 无法在Bokeh中使用鼠标悬停工具显示NetworkX中的标签

Python 无法在Bokeh中使用鼠标悬停工具显示NetworkX中的标签,python,graph,bokeh,networkx,Python,Graph,Bokeh,Networkx,我一直在尝试为Bokeh的一项访谈研究创建一个覆盖受访者和答案类别的交互式图表,但我无法在鼠标悬停在节点上时显示标签。我曾尝试使用来自的解决方案,但我一直遇到与Kristada673在评论中描述的相同的问题 有什么想法吗 from bokeh.io import show, output_file from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, TapTool, BoxSelectTool from bo

我一直在尝试为Bokeh的一项访谈研究创建一个覆盖受访者和答案类别的交互式图表,但我无法在鼠标悬停在节点上时显示标签。我曾尝试使用来自的解决方案,但我一直遇到与Kristada673在评论中描述的相同的问题

有什么想法吗

from bokeh.io import show, output_file
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, TapTool, BoxSelectTool
from bokeh.models.graphs import from_networkx, NodesAndLinkedEdges, EdgesAndLinkedNodes
from bokeh.palettes import Spectral4
G=nx.Graph()

respondent = ["TI01", "TI02", "TI03", "TT01", "TT02", "TT03"]  #Respondents

#             0                        1                       2                   3           4                             5              6                     7              8              9                10                11                    12             13                 14
code=["Previous Teaching", "Avoidance Strategies", "Spelling by Sound", "Homophones", "Individual Oral Feedback", "Written Feedback", "Articles", "Overwhelmed Students", "Verb Tenses", "Punctuation", "Formal Register", "Run-on Sentences", "Matrices/Rubrics", "Peer-review", "Sentence Structures"]  #Substantive Codes

G.add_nodes_from(respondent)

G.add_nodes_from(code)

#First Pilot
#TI01
G.add_edges_from([("TI01", code[0]), ("TI01", code[2]), ("TI01", code[5])])
#TI02
G.add_edges_from([("TI02", code[2]), ("TI02", code[3]), ("TI02", code[0]), ("TI02", code[4]), ("TI02", code[5])])
#TI03
G.add_edges_from([("TI03", code[0]), ("TI03", code[1]),("TI03", code[5])])

#Second Pilot
#TT01
G.add_edges_from([("TT01", code[2]), ("TT01", code[3]), ("TT01", code[4]), ("TT01", code[5])])
#TT02
G.add_edges_from([("TT02", code[6]), ("TT02", code[9]), ("TT02", code[8]), ("TT02", code[10]), ("TT02", code[0]), ("TT02", code[13])])
#TT03
G.add_edges_from([("TT03", code[14]), ("TT03", code[0]),("TT03", code[13]), ("TT03", code[12]), ("TT03", code[9]), ("TT03", code[11])])


plot = Plot(plot_width=600, plot_height=600,
            x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))

plot.title.text = "Possible Substantive Codes Pilot Interviews"

hover = HoverTool(tooltips=[('respondent','code')])
plot.add_tools(hover, TapTool())

graph_renderer = from_networkx(G, nx.circular_layout, scale=1, center=(0,0))

graph_renderer.node_renderer.glyph = Circle(size=20, fill_color=Spectral4[0])
graph_renderer.node_renderer.selection_glyph = Circle(size=15, fill_color=Spectral4[2])
graph_renderer.node_renderer.hover_glyph = Circle(size=15, fill_color=Spectral4[1])


graph_renderer.edge_renderer.glyph = MultiLine(line_color="#CCCCCC", line_alpha=0.8, line_width=5)
graph_renderer.edge_renderer.selection_glyph = MultiLine(line_color=Spectral4[2], line_width=5)
graph_renderer.edge_renderer.hover_glyph = MultiLine(line_color=Spectral4[1], line_width=5)

graph_renderer.selection_policy = NodesAndLinkedEdges()
graph_renderer.inspection_policy = NodesAndLinkedEdges()


plot.renderers.append(graph_renderer)

output_file("interactive_graphs.html")
show(plot)

通过在HoverTool中引用“@index”并使用输出文件而不是查看新的浏览器窗口,解决了这个问题。标签在新浏览器窗口中仍不起作用,但在浏览器中打开输出文件时起作用

如果您遇到了相同的问题,请尝试使用代码生成的文件来查看它是否已修复


这不是一个完整的解决方案,但已为我解决。

这是通过在HoverTool中引用“@index”并使用输出文件而不是查看新的浏览器窗口来解决的。标签在新浏览器窗口中仍不起作用,但在浏览器中打开输出文件时起作用

如果您遇到了相同的问题,请尝试使用代码生成的文件来查看它是否已修复

不是一个完整的解决方案,但解决了我的目的