plot - 在networkx中重新排列图中的节点和边
问题描述
我使用networkx(Python)的光谱布局绘制了下图。看起来同一张图可以重新排列成一个 3D 立方体,其中的层次关系会更清晰。所有下标“orth”的都可以在同一平面上,即低于所有下标“lex”(它们本身都在一个平面上);这低于所有那些下标的“sem”(它们也占据同一平面)。
我有两个问题:是否有任何绘图布局可以使分层性质变得明显?如果我上面描述的平面结构可以完成这项工作,我该如何实现呢?
代码如下:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.DiGraph()
edges = [('$x_{orth}$', '$e_{orth}$'),\
('$r_{orth}$', '$e_{orth}$'),\
('$e_{orth}$', '$y_{lex}$'),\
('$r_{lex}$', '$x_{orth}$'), \
('$y_{lex}$', '$r_{orth}$'), \
('$y_{lex}$', '$x_{lex}$'), \
('$y_{lex}$', '$y_{lex}$'),\
('$x_{lex}$', '$e_{lex}$'),\
('$r_{lex}$', '$e_{lex}$'),\
('$e_{lex}$', '$y_{sem}$'),\
('$r_{sem}$', '$x_{lex}$'), \
('$y_{sem}$', '$r_{lex}$'), \
('$y_{sem}$', '$x_{sem}$'), \
('$y_{sem}$', '$y_{sem}$'), \
('$x_{sem}$', '$e_{sem}$'),\
('$r_{sem}$', '$e_{sem}$'),\
('$e_{sem}$', '$y_{mng}$'),\
('$y_{mng}$', '$r_{sem}$'), \
('$y_{mng}$', '$y_{mng}$')]
G.add_edges_from(edges)
# separate calls to draw nodes and edges
pos = nx.spectral_layout(G)
nx.draw_networkx_nodes(G, pos,node_size = 500)
nx.draw_networkx_labels(G, pos)
nx.draw_networkx_edges(G, pos, edgelist=edges, edge_color='black', arrows=True)
plt.show()
enter code here
解决方案
推荐阅读
- python-3.x - 如何在python中迭代特定值作为其范围的动态嵌套循环?
- html - CSS 中的下拉样式问题
- java - 在java中使用多态对json进行序列化和反序列化时出错
- python - 我如何使用 fastai (kaggle) 保存和加载模型
- python - Transformers Longformer IndexError: index out of range in self
- javascript - Node.js Chart.js 实时图表更新
- spring-boot - SpringBoot + Gradle + Mapstruct 失败,在运行时找不到 bean
- python - Discord 消息获取:int() 的无效文字,基数为 10:'guild id'
- css - 在反应中为蚂蚁设计卡提供边界半径
- c# - 等待和事件处理程序