1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| from pprint import pprint
import networkx as nx import matplotlib.pyplot as plt
def list_fonts(): from matplotlib.font_manager import FontManager fm = FontManager() pprint(set([f.name for f in fm.ttflist]))
def draw(): """ 列出系统的字体,然后找一个支持中文的 """ plt.rcParams['font.sans-serif'] = ['AR PL UKai CN'] G = nx.Graph() G.add_edges_from([('你呀你呀', 2), (2, 3), (3, 1)])
pos = nx.spring_layout(G) nx.draw(G, pos, with_labels=True) plt.savefig('graph.png') plt.show()
if __name__ == '__main__': draw()
|