Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
1.0KB

  1. import networkx as nx
  2. from matplotlib import pyplot as plt
  3. import clifford
  4. import numpy as np
  5. from graphstate import GraphState
  6. VOP_COLORS = ["red", "green", "blue", "orange", "yellow", "purple", "black", "white"]
  7. def draw(state, filename="out.pdf", pos=None, ns=500):
  8. """ Draw a graph with networkx layout """
  9. plt.clf()
  10. graph = nx.from_edgelist(state.edgelist())
  11. pos = nx.spring_layout(graph) if pos==None else pos
  12. colors = [VOP_COLORS[vop % len(VOP_COLORS)] for vop in state.vops.values()]
  13. nx.draw_networkx_nodes(graph, pos, node_color="white", node_size=ns)
  14. nx.draw_networkx_nodes(graph, pos, node_color=colors, node_size=ns, alpha=.4)
  15. nx.draw_networkx_edges(graph, pos, edge_color="gray")
  16. nx.draw_networkx_labels(graph, pos, font_family="FreeSans")
  17. # tables.name_of(v)
  18. labels = {i: "no name" for i, v in state.vops.items()}
  19. pos = {k: v + np.array([0, -.1]) for k, v in pos.items()}
  20. nx.draw_networkx_labels(graph, pos, labels, font_family="FreeSans")
  21. plt.axis('off')
  22. plt.savefig(filename)
  23. return pos