我正在尝试从距离矩阵中绘制图表。该代码工作正常,并给了我一个图像。图像很大,但所有节点都打包在一起。我想增加节点之间的空间。我希望节点更加分开而不是扩大。
我试过 Graphviz NEATO,但它的问题是它只支持 100 个节点,因为我有 1000 个节点,所以它显示了 10 个集群,每个集群有 100 个节点。
我的整体代码 -
import networkx as nx
import pickle
import matplotlib.pyplot as plt
print "~~~Unpickle."
p_file = open('pickles/names')
Names = pickle.load(p_file)
p_file.close()
p_file = open('pickles/distance')
Dist = pickle.load(p_file)
p_file.close()
G = nx.Graph()
print "~~~Inserting Nodes."
for store in Names:
G.add_node(store)
print "~~~Inserting Edges."
for i in range(601):
for j in range(601):
if Names[i]!=Names[j]:
G.add_edge(Names[i],Names[j],weight=Dist[i][j])
print "~~~Drawing Graph."
nx.draw(G,pos,node_color='#A0CBE2',edge_color='none',width=1, edge_cmap=plt.cm.Blues, with_labels=False)
print "~~~Saving Figure."
plt.savefig("graph.png", dpi=500, facecolor='w', edgecolor='w',orientation='portrait', papertype=None, format=None,transparent=False, bbox_inches=None, pad_inches=0.1)
print "~~~Success!"
输出(删除边缘和标签):
具有 600 个节点的 Graphvix NEATO 的输出 -