python - 如何在python中可视化复杂的图形?
问题描述
我有一个非常复杂的图表,其中包含许多节点和边。为了更好地理解,我想可视化图表。我与很多图书馆合作,但没有得到我想要的。
这篇文章很棒,但我无法pos
为我的图表定义属性。随机几何图pos
默认有一个属性。
number of nodes = 567
number of edges = 846
我使用 nx.random_layout() 为我的节点定义“pos”属性。我的图表名称是 taradodGraph
pos = nx.random_layout(taradodGraph)
dmin = 1
ncenter = 0
for n in pos:
x, y = pos[n]
d = (x - 0.5)**2 + (y - 0.5)**2
if d < dmin:
ncenter = n
dmin = d
# color by path length from node near center
p = dict(nx.single_source_shortest_path_length(taradodGraph, ncenter))
plt.figure(figsize=(8, 8))
nx.draw_networkx_edges(taradodGraph, pos, nodelist=[ncenter], alpha=0.4)
nx.draw_networkx_nodes(taradodGraph, pos, nodelist=list(p.keys()),
node_size=80,
node_color=list(p.values()),
cmap=plt.cm.Reds_r)
plt.xlim(-0.05, 1.05)
plt.ylim(-0.05, 1.05)
plt.axis('off')
plt.savefig('foo.png')
plt.show()
解决方案
推荐阅读
- javascript - 奇怪的断点行为(移动到不同的位置,并且出现了更多的断点)
- jquery - flatpickr maxDate 配置
- java - 无法为 /com/sun/jna/win32-x86/jnidispatch.dll 库创建临时文件:系统找不到路径
- android - ConstraintLayout 的大小不正确(在实践中)
- java - 如何反编译带有加密类的 .jar 程序
- php - 如何修复 class-wp-meta-query 中的“trim() 需要参数 1”-> 要选择哪个 Meta Key?
- android - 如何在单击按钮时删除 recyclerview 的 ckeck 框选中项?
- python - 从具有相同索引的矩阵生成列表
- armadillo - 当我将犰狳链接到 clblas 时未定义的符号 _zgemm_
- android - 从一台设备向另一台设备发送推送通知