【发布时间】:2015-08-21 18:05:02
【问题描述】:
所以我创建了一种非常幼稚(可能效率低下)的生成哈希图的方法。
问题:
我有 4 个维度... p q r s .
我想统一显示它(tesseract),但我不知道如何重塑它。 如何在 Python 中重塑 networkx 图?
我见过一些使用 spring_layout() 和 draw_circular() 的人的例子,但它的形状与我所寻找的不同,因为它们不统一。
有没有办法重塑我的图表并使其统一?(即将我的哈斯图重塑为正方体形状(最好使用nx.draw())
这是我目前的样子:
这是我生成 N 维哈希图的代码
#!/usr/bin/python
import networkx as nx
import matplotlib.pyplot as plt
import itertools
H = nx.DiGraph()
axis_labels = ['p','q','r','s']
D_len_node = {}
#Iterate through axis labels
for i in xrange(0,len(axis_labels)+1):
#Create edge from empty set
if i == 0:
for ax in axis_labels:
H.add_edge('O',ax)
else:
#Create all non-overlapping combinations
combinations = [c for c in itertools.combinations(axis_labels,i)]
D_len_node[i] = combinations
#Create edge from len(i-1) to len(i) #eg. pq >>> pqr, pq >>> pqs
if i > 1:
for node in D_len_node[i]:
for p_node in D_len_node[i-1]:
#if set.intersection(set(p_node),set(node)): Oops
if all(p in node for p in p_node) == True: #should be this!
H.add_edge(''.join(p_node),''.join(node))
#Show Plot
nx.draw(H,with_labels = True,node_shape = 'o')
plt.show()
我想像这样重塑它:
如果有人知道制作哈斯图的更简单方法,请分享一些智慧,但这不是本文的主要目的。
【问题讨论】:
-
通过从
shell_layout调整k,您可以获得更少堆叠的图形。使用 0.48 的值,我最终得到了一些可读的东西,但不是很接近你的期望。 -
嗨@cyrbil 我认为必须有一种方法来获得 N 维 2D 投影的坐标,因为这基本上就是 nx.hypercube_graph(3) 发生的事情
-
如果您还需要什么/我的回答中有什么不清楚的地方,请在 cmets 中告诉我。否则 - 享受可视化的乐趣 - 将不胜感激:)
标签: python matplotlib nodes shape networkx