NetworkX 中大图可视化的问题
Troubles with visualization of big graph in NetworkX
我有一个具有 47 个节点和 90 个加权边的无向图。我想得到这张图的图像,但我得到了一些奇怪的东西 [1]:节点彼此重叠。我想修复它,但我不知道如何修复。下面是绘图代码:
import networkx as nx
import matplotlib.pyplot as plt
import pylab
def show_graph(G):
pos = nx.spring_layout(G)
nx.draw(G, pos, node_color='#A0CBE2', edge_color='#BB0000', width=2, edge_cmap=plt.cm.Blues, with_labels=True)
plt.savefig("graph.png", dpi=1000)
# 2 way
# nx.draw(G, with_labels=True)
# plt.draw()
# plt.show()
f = open("europe.txt")
G = nx.Graph()
lines = f.readlines()
edges = list()
for line in lines:
tmp = line.split(', ')
tmp[2] = int(tmp[2])
edges.append(tmp)
G.add_weighted_edges_from(edges)
show_graph(G)
图片[1]:https://i.stack.imgur.com/B5Slx.png
我的解决方案是:
import networkx as nx
import matplotlib.pyplot as plt
和函数
def show_graph(G):
plt.subplot(111)
nx.draw(G, pos=nx.planar_layout(G), node_color='r', edge_color='b', with_labels=True)
plt.show()
平面布局适合我的情况
我有一个具有 47 个节点和 90 个加权边的无向图。我想得到这张图的图像,但我得到了一些奇怪的东西 [1]:节点彼此重叠。我想修复它,但我不知道如何修复。下面是绘图代码:
import networkx as nx
import matplotlib.pyplot as plt
import pylab
def show_graph(G):
pos = nx.spring_layout(G)
nx.draw(G, pos, node_color='#A0CBE2', edge_color='#BB0000', width=2, edge_cmap=plt.cm.Blues, with_labels=True)
plt.savefig("graph.png", dpi=1000)
# 2 way
# nx.draw(G, with_labels=True)
# plt.draw()
# plt.show()
f = open("europe.txt")
G = nx.Graph()
lines = f.readlines()
edges = list()
for line in lines:
tmp = line.split(', ')
tmp[2] = int(tmp[2])
edges.append(tmp)
G.add_weighted_edges_from(edges)
show_graph(G)
图片[1]:https://i.stack.imgur.com/B5Slx.png
我的解决方案是:
import networkx as nx
import matplotlib.pyplot as plt
和函数
def show_graph(G):
plt.subplot(111)
nx.draw(G, pos=nx.planar_layout(G), node_color='r', edge_color='b', with_labels=True)
plt.show()
平面布局适合我的情况