[英]Is it possible to create a graph permutation in python?
我寫了一個簡單的置換函數,我想繪制它的輸出。 甚至有可能嗎?
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']
我很難找到有關排列圖的材料,因此將不勝感激。
這就是我想要實現的
謝謝!!!
我不知道你在函數中做了什么,但我發現了如何使用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()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.