Networkx图形不是平面的

2024-05-19 00:24:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图画一个网络图。我的代码非常简单。对于小案例研究,此代码运行良好。但对于具有更多顶点和圆弧的更大样本,我得到G不是平面误差。这个错误的原因是什么

D:\Anaconda3\lib\site-packages\networkx\drawing\layout.py in planar_layout(G, scale, center, dim) 945 is_planar, embedding = nx.check_planarity(G) 946 if not is_planar: --> 947 raise nx.NetworkXException("G is not planar.") 948 pos = nx.combinatorial_embedding_to_pos(embedding) 949 node_list = list(embedding)

NetworkXException:G不是平面

def createAttackGraphNonPlanar(pos):
    G=nx.DiGraph(directed=True)
    G.add_nodes_from([nodes_map[n] for n in nodes])
    print(G.nodes())
    
    
    G.add_edges_from([  (nodes_map[e[0]],nodes_map[e[1]]) for e in arcs])
 
    nx.draw_planar(G, pos=pos, node_size=30, node_color='red', with_labels = True)

Tags: inposnodetruemapisnotembedding
1条回答
网友
1楼 · 发布于 2024-05-19 00:24:19

函数draw_planar用于从documentation中绘制planar graph

Draw a planar networkx graph with planar layout.

并非所有的图都是平面图

要绘制任何图形,请使用draw,例如(仅用于演示):

import matplotlib.pyplot as plt
G = nx.dodecahedral_graph()
nx.draw(G)  # networkx draw()
plt.draw()  # pyplot draw()

有关绘制图形的更多信息,请参见此link

相关问题 更多 >

    热门问题