Python 2.7 NetworkX (make it interactive)

I am new to NetworkX. Right now, I am able to connect all nodes to this particular node. What I want to do next is to make it interactive, for example. able to make each of the nodes move by dragging it with the cursor. I know that I need to use matplotlib, but I'm not sure how to use it. Can anybody help me?

enter image description here

My codes are:

import matplotlib.pyplot as plt
import networkx as nx
import itertools

d = [name of nodes]
f = [number per nodes]

for i in d:
  G.add_edge('"' + i + '"',b)

pos=nx.fruchterman_reingold_layout(G, k=0.5, iterations=5)

nx.draw_networkx_nodes(G,pos,node_size=130, node_color="white")

nx.draw_networkx_edges(G,pos, width=0.2,alpha=1,edge_color='black')

nx.draw_networkx_labels(G,pos,font_size=7,font_family='sans-serif')

for i,j in itertools.izip(d,f):
    nx.draw_networkx_edge_labels(G,pos, {('"' + i + '"',b):j}, font_size=7, label_pos= 0.80)

plt.axis('off')
plt.show()
+4
source share
2 answers

This seems to be hard to do with matplotlib (it is not intended for this). The Networkx drawing module is pretty bad, it mainly uses a custom scatter plot for nodes, etc.

I suggest another solution:

, NetworkX, - . , node .

:

+3

Matplotlib .

, NetworkX GEXF, , , . Gephi. , , -.

+2

Source: https://habr.com/ru/post/1599233/


All Articles