参考
https://www.cnblogs.com/openqt/p/4305530.html https://www.cnblogs.com/bonelee/p/14367378.html
代码:
# -*- encoding: utf-8 -*-
from matplotlib import pyplot as plt
import networkx as nx
def display_toycase():
N = {
'a': set('bcdef'),
'b': set('ce'),
'c': set('d'),
'd': set('e'),
'e': set('f'),
'f': set('cgh'),
'g': set('fh'),
'h': set('fg'),
}
G = nx.DiGraph(N)
nx.draw(G, with_labels=True,
node_color='r',
edge_color='b',
font_color='g',
font_size=16)
plt.axis('off')
plt.savefig("labels_and_colors.png") # save as png
plt.show()
def displayZ_toycase3():
# Sample graph
G = nx.Graph()
G.add_edges_from([('a', 'b'), ('b', 'c'), ('b', 'e'),('a', 'e')])
# G.add_edge('a', 'b')
# G.add_edge('b', 'c')
# G.add_edge('b', 'e')
# G.add_edge('a', 'e')
# labels = {(0, 1): 'foo', (2, 3): 'bar'}
labels = {('a', 'b'): 0.5, ('b', 'c'): 0.6}
pos = nx.spring_layout(G)
nx.draw(G, pos, with_labels=True)
nx.draw_networkx_edge_labels(G, pos, edge_labels=labels, font_size=30)
import pylab as plt
plt.axis('off')
plt.savefig("labels_and_colors.png") # save as png
plt.show()
|