我正在使用NetworkX和Bokeh制作网络节点图。我正在使用NetworkX的“spring_layout”自动为每个节点生成位置。然而,我无法弄清楚如何在我的图形上拖动节点(并使边跟随任何拖动节点移动)。
如何为我的NetworkX/Bokeh图启用节点拖动功能?
我尝试使用Bokeh的“PointDrawTool”工具,但是即使该工具在我的图形旁边的工具栏中呈现和显示,它也无法正常工作。
我希望这些节点可以被拖动。我想点击一个节点并拖动它,以改变其位置。 2019年5月14日编辑: 我的引入:
如何为我的NetworkX/Bokeh图启用节点拖动功能?
我尝试使用Bokeh的“PointDrawTool”工具,但是即使该工具在我的图形旁边的工具栏中呈现和显示,它也无法正常工作。
plot = Plot(plot_width=1000, plot_height=1000,
x_range=Range1d(-1.1,1.1), y_range=Range1d(-1.1,1.1))
plot.title.text = "Network Graph"
graph_renderer = from_networkx(G, nx.spring_layout)
plot.add_tools(HoverTool(tooltips=[("ID", "@index"), ("Internal IP", "@Internal")]), PointDrawTool(renderers = [graph_renderer.node_renderer], empty_value = 'black'), TapTool(), BoxSelectTool(), BoxEditTool(), BoxZoomTool(), PanTool(), WheelZoomTool(), ZoomInTool(), ZoomOutTool(), SaveTool(), UndoTool())
graph_renderer.node_renderer.glyph = Circle(size=10, fill_color=Spectral4[0])
graph_renderer.node_renderer.selection_glyph = Circle(size=10, fill_color=Spectral4[2])
graph_renderer.node_renderer.hover_glyph = Circle(size=10, fill_color=Spectral4[1])
graph_renderer.edge_renderer.glyph = MultiLine(line_color="#CCCCCC", line_alpha=0.8, line_width=1)
graph_renderer.edge_renderer.selection_glyph = MultiLine(line_color=Spectral4[2], line_width=3)
graph_renderer.edge_renderer.hover_glyph = MultiLine(line_color=Spectral4[1], line_width=3)
graph_renderer.selection_policy = NodesAndLinkedEdges()
graph_renderer.inspection_policy = NodesAndLinkedEdges()
plot.renderers.append(graph_renderer)
output_file("interactive_graphs.html")
show(plot)
我希望这些节点可以被拖动。我想点击一个节点并拖动它,以改变其位置。 2019年5月14日编辑: 我的引入:
import pandas as pd
import numpy as np
import networkx as nx
from bokeh.io import show, output_file
from bokeh.models import Plot, Range1d, MultiLine, Circle, HoverTool, TapTool, BoxEditTool, BoxSelectTool, BoxZoomTool, ResetTool, PanTool, WheelZoomTool, ZoomInTool, ZoomOutTool, SaveTool, UndoTool, PointDrawTool
from bokeh.models.graphs import from_networkx, NodesAndLinkedEdges, EdgesAndLinkedNodes
from bokeh.palettes import Spectral4
import warnings
import matplotlib.pyplot as plt
%matplotlib notebook
from IPython.display import display, HTML
from IPython.core.interactiveshell import InteractiveShell
bokeh
的子模块的。 - vurmuxnetgraph
,您可以在这里找到它。非常希望听到您的反馈,特别是如果它不能满足您的需求。;-) - Paul Brodersen