ラベルの大きさを調整したくて困っています。
出来ればノードの大きさを参照できるようにできれば幸いです。
よろしくお願いします。
python
import matplotlib.pyplot as plt import networkx as nx G = nx.Graph() G.add_nodes_from(["A","B","C","D","E","F"]) G.add_edges_from([("A","B"),("B","C"),("B","F"),("C","D"),("C","E"),("C","F"),("B","F")]) print("number of nodes:",G.number_of_nodes()) print("nodes:",G.nodes()) print("number of edges:",G.number_of_edges()) print("edges:",G.edges()) print("degrees:",G.degree()) #ノードの大きさを決定 #ネットワーク全体の次数の平均値を計算 average_deg = sum(d for n,d in G.degree()) / G.number_of_nodes() #ノードの次数に比例するようにサイズを設定 sizes = [300 * deg / average_deg for node,deg in G.degree()] colors = ["lightblue","green","red","cyan","magenta","yellow"] nodes_sorted_by_degree = sorted(G.degree(),key = lambda x: x[1],reverse = True) print(nodes_sorted_by_degree) colors_dict = dict(zip(G.nodes(),colors)) colors_sorted = [colors_dict[node] for node, _ in nodes_sorted_by_degree] print(colors_sorted) plt.figure(figsize = (10,5)) plt.subplot(121) nx.draw(G, with_labels = True, node_color = colors, edge_color = "black", node_size = sizes, width = 5) x,height = list(zip(*nodes_sorted_by_degree)) plt.subplot(122) plt.xlabel("Number of degrees") plt.ylabel("Name of node") plt.barh(x, height, color = colors_sorted) plt.show()
まだ回答がついていません
会員登録して回答してみよう