我编写了一个简单的排列函数,我想用图表表示它的输出。这可能吗?
from itertools import permutations
def permutate(string):
letters = [x for x in string]
perms = list(permutations(letters, len(letters)))
p_set = set([''.join(i) for i in perms])
return p_set
a = list(permutate('abab'))
# output: ['abba', 'abab', 'aabb', 'baba', 'baab', 'bbaa']
我很难找到有关排列图的 Material ,因此我们将不胜感激。
这就是我想要实现的目标
谢谢!!!
最佳答案
我不知道你在函数中做了什么,但找到了如何使用 networkx
和 matplotlib
制作你想要的图表。
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edges_from([(0, 1), (1, 2), (2, 3), (3, 4), (1, 4), (2, 5),
(0, 5), (1, 5), (3, 5), (2, 4), (0, 2), (1, 3)])
fig, axes = plt.subplots(figsize=(8, 6))
nx.draw(G, ax=axes, pos=nx.circular_layout(G), with_labels=True)
plt.show()
关于python - 是否可以在 python 中创建图排列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69942020/