NetworkX是否有内置的方法可以按照邻接矩阵频率/节点-节点频率来缩放节点和边缘的大小? 我正在尝试根据邻接矩阵频率和节点-节点频率来调整节点和文本的大小,以及根据节点-节点频率来调整边缘的权重。我已经为图形创建了一个频率属性,但这并不能解决将信息传递到图形中关于节点-节点频率的问题。
因此,这是一个两部分的问题:
1) 将邻接矩阵转换成NetworkX图的最佳实践是什么?
2) 我如何使用这些信息来缩放节点的大小和边缘的权重?
我尝试过设置标签的字体大小,但没有成功: font_size = nx.get_node_attributes(G, 'frequency') + 8
因此,这是一个两部分的问题:
1) 将邻接矩阵转换成NetworkX图的最佳实践是什么?
2) 我如何使用这些信息来缩放节点的大小和边缘的权重?
## Compute Graph (G)
G = nx.Graph(A)
## Add frequency of word as attribute of graph
def Freq_Attribute(G, A):
frequency = {} # Dictionary Declaration
for node in G.nodes():
frequency[str(node)] = A[str(node)][str(node)]
return nx.set_node_attributes(G, 'frequency', frequency)
Freq_Attribute(g,A) # Adds attribute frequency to graph, for font scale
## Plot Graph with Labels
plt.figure(1, figsize=(10,10))
# Set location of nodes as the default
pos = nx.spring_layout(G, k=0.50, iterations=30)
# Nodes
node_size = 10000
nodes1 = nx.draw_networkx_nodes(G,pos,
node_color='None',
node_size=node_size,
alpha=1.0) # nodelist=[0,1,2,3],
nodes1.set_edgecolor('#A9C1CD') # Set edge color to black
# Edges
edges = nx.draw_networkx_edges(G,pos,width=1,alpha=0.05,edge_color='black')
edges.set_zorder(3)
# Labels
nx.draw_networkx_labels(G,pos,labels=nx.get_node_attributes(G,'label'),
font_size=16,
font_color='#062D40',
font_family='arial') # sans-serif, Font=16
# node_labels = nx.get_node_attributes(g, 'name')
# Use 'g.graph' to find attribute(s): {'name': 'words'}
plt.axis('off')
#plt.show()
我尝试过设置标签的字体大小,但没有成功: font_size = nx.get_node_attributes(G, 'frequency') + 8