Anders and Briegel in Python
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

viz.py 1.2KB

il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
il y a 8 ans
12345678910111213141516171819202122232425262728293031323334353637383940
  1. """
  2. Utility function for plotting graphs nicely
  3. """
  4. import networkx as nx
  5. from matplotlib import pyplot as plt
  6. from graph import *
  7. import clifford
  8. import numpy as np
  9. VOP_COLORS = ["red", "green", "blue", "orange", "yellow", "purple", "black", "white"]
  10. def draw(graph, vops, filename="out.pdf", pos=None, ns=500):
  11. """ Draw a graph with networkx layout """
  12. plt.clf()
  13. g = nx.from_edgelist(edgelist(graph))
  14. pos = nx.spring_layout(g) if pos==None else pos
  15. colors = [VOP_COLORS[vop % len(VOP_COLORS)] for vop in vops]
  16. nx.draw_networkx_nodes(g, pos, node_color="white", node_size=ns)
  17. nx.draw_networkx_nodes(g, pos, node_color=colors, node_size=ns, alpha=.4)
  18. nx.draw_networkx_edges(g, pos, edge_color="gray")
  19. nx.draw_networkx_labels(g, pos)
  20. labels = {i: clifford.name_of(vops[i]) for i in g.nodes()}
  21. pos = {k: v + np.array([0, -.1]) for k, v in pos.items()}
  22. nx.draw_networkx_labels(g, pos, labels)
  23. plt.axis('off')
  24. plt.savefig(filename)
  25. return pos
  26. if __name__ == '__main__':
  27. g, vops = graph()
  28. add_edge(g, 0, 1)
  29. add_edge(g, 1, 3)
  30. add_edge(g, 3, 2)
  31. add_edge(g, 3, 0)
  32. add_edge(g, 2, 0)
  33. edgelist(g)
  34. draw(g, vops)