画有向图
from matplotlib import pyplot as plt
import networkx as nx
# directed graph
G=nx.DiGraph()
G.add_nodes_from([1,2,3])
G.add_edges_from([(1,2),(1,3)])
nx.draw_networkx(G)
plt.show()
调整节点之间的间距
pos = nx.spring_layout(G,k=0.15,iterations=20)
# k controls the distance between the nodes and varies between 0 and 1
# iterations is the number of times simulated annealing is run
# default k =0.1 and iterations=50
from matplotlib import pyplot as plt
import networkx as nx
# directed graph
G=nx.DiGraph()
G.add_edges_from([(1, 2), (1, 3)])
# G.add_node(1)
G.add_edge(1, 2)
G.add_node("spam") # adds node "spam"
G.add_nodes_from("spam") # adds 4 nodes: 's', 'p', 'a', 'm'
G.add_edge(3, 'm')
G.remove_node(3)
G.add_node(1, time='5pm')
print(G.nodes[1]) # 显示{'time': '5pm'}
# pr