【问题标题】:Troubles with visualization of big graph in NetworkXNetworkX中大图可视化的问题
【发布时间】:2021-03-31 15:53:17
【问题描述】:

我有一个有 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

【问题讨论】:

    标签: python graph networkx


    【解决方案1】:

    我的解决方案是:

    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()
    

    平面布局适合我的情况

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-27
      • 2016-07-11
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 2013-11-03
      • 1970-01-01
      相关资源
      最近更新 更多