我想知道如何在Python的NetworkX中创建可单击的节点。 例如,我点击一个节点,它就会调用一个函数
我一直在做研究,但没能找到固溶体。下面是一些示例代码:
import networkx as nx
from pylab import rcParams, matplotlib
import seaborn as sb
import matplotlib.pyplot as plt
def nodeNetworkGraph(nodes_found):
rcParams['figure.figsize'] = 8,4
sb.set_style('whitegrid')
G = nx.DiGraph()
label_dict = {}
if nodes_found == 0:
G = nx.gn_graph(1)
label_dict.update({0: "No Nodes"})
else:
for i in range(nodes_found):
if i+1 == nodes_found & nodes_found != 1:
label_dict.update({i: i+1})
break
elif nodes_found == 1:
G = nx.gn_graph(nodes_found)
label_dict.update({i: i+1})
else:
label_dict.update({i: i+1})
G.add_edge(i,i+1)
G = G.to_undirected()
G.remove_edges_from(G.edges())
nx.draw_circular(G, labels=label_dict, node_color='yellow', with_labels=True)
plt.show()
nodeNetworkGraph(40)
任何帮助都将不胜感激。 谢谢:)
目前没有回答
相关问题 更多 >
编程相关推荐