Anders and Briegel in Python
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425
  1. import networkx as nx
  2. from matplotlib import pyplot as plt
  3. import tables
  4. import numpy as np
  5. from graph 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. labels = {i: tables.name_of(v) for i, v in state.vops.items()}
  18. pos = {k: v + np.array([0, -.1]) for k, v in pos.items()}
  19. nx.draw_networkx_labels(graph, pos, labels, font_family="FreeSans")
  20. plt.axis('off')
  21. plt.savefig(filename)
  22. return pos