改善Python NetworkX图形布局 [英] Improving Python NetworkX graph layout

查看:1125
本文介绍了改善Python NetworkX图形布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在可视化使用python-networkx创建的图形时遇到一些问题,我希望能够减少混乱并调节节点之间的距离(我也尝试过spring_layout,它只是以椭圆形式布置节点) .请指教.

I am having some problems in visualizing the graphs created with python-networkx, I want to able to reduce clutter and regulate the distance between the nodes (I have also tried spring_layout, it just lays out the nodes in an elliptical fashion). Please advise.

部分代码:

nx.draw_networkx_edges(G, pos, edgelist=predges, edge_color='red', arrows=True)
nx.draw_networkx_edges(G, pos, edgelist=black_edges, arrows=False, style='dashed')
# label fonts
nx.draw_networkx_labels(G,pos,font_size=7,font_family='sans-serif')
nx.draw_networkx_edge_labels(G,pos,q_list,label_pos=0.3)

推荐答案

在networkx中,值得检查 nx.graphviz_layout .

In networkx, it's worth checking out the graph drawing algorithms provided by graphviz via nx.graphviz_layout.

我在neato上取得了不错的成绩,但其他可能的投入是

I've had good success with neato but the other possible inputs are

  • dot-有向图的分层"或分层图.如果边缘具有方向性,这是默认使用的工具.

  • dot - "hierarchical" or layered drawings of directed graphs. This is the default tool to use if edges have directionality.

neato-弹簧模型"布局.如果图形不是太大(大约100个节点)并且您对此一无所知,这是默认使用的工具.最小化一个全局能量函数,这等效于统计多维尺度.

neato - "spring model'' layouts. This is the default tool to use if the graph is not too large (about 100 nodes) and you don't know anything else about it. Neato attempts to minimize a global energy function, which is equivalent to statistical multi-dimensional scaling.

fdp-弹簧模型"布局类似于neato的布局,但这是通过减小力而不是消耗能量来实现的.

fdp - "spring model'' layouts similar to those of neato, but does this by reducing forces rather than working with energy.

sfdp-fdp的多比例版本,用于大图的布局.

sfdp - multiscale version of fdp for the layout of large graphs.

twopi-在Graham Wills 97之后的径向布局.根据与给定根节点的距离,将节点放置在同心圆上.

twopi - radial layouts, after Graham Wills 97. Nodes are placed on concentric circles depending their distance from a given root node.

circo-在Six和Tollis 99,Kauffman和Wiese 02之后的圆形布局.这适用于某些具有多个循环结构的图,例如某些电信网络.

circo - circular layout, after Six and Tollis 99, Kauffman and Wiese 02. This is suitable for certain diagrams of multiple cyclic structures, such as certain telecommunications networks.

通常,图形绘制是一个难题.如果这些算法还不够,则必须编写自己的算法或让networkx分别绘制零件.

In general, graph drawing is a hard problem. If these algorithms are not sufficient, you'll have to write your own or have networkx draw parts individually.

这篇关于改善Python NetworkX图形布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆