NetworkX是否有一种内置的方式来缩放与邻接矩阵频率/节点节点频率成比例的节点和边?我试图根据邻接矩阵的频率来调整节点和文本的大小,并根据节点节点的频率调整边缘的权重。我已经为图创建了一个frequency属性,但这并不能解决向图传递有关节点节点频率的信息的问题。在
所以两部分的问题:
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()
我试过设置标签字体大小,但没用 字体大小=nx.get_node_属性(G,“频率”)+8)
为了满足您的需要,我尝试了以下方法:
{a1}
首先,邻接反应不是用矩阵的形式给出的,但是这太单调了。在
其次,^{} 不允许标签使用不同的字体大小。我帮不上忙。在
但是,最后一个边的大小和宽度允许。因此,它们分别根据其频率和输入频率的总和进行缩放。在
希望有帮助。在
相关问题 更多 >
编程相关推荐