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.

20 rindas
667B

  1. import networkx as nx
  2. import numpy as np
  3. import graphstate
  4. import clifford
  5. import util
  6. class NXGraphState(graphstate.GraphState, nx.Graph):
  7. """ This is GraphState with NetworkX-like abilities """
  8. def __init__(self, *args, **kwargs):
  9. graphstate.GraphState.__init__(self, *args, **kwargs)
  10. def layout(self):
  11. """ Automatically lay out the graph """
  12. pos = nx.spring_layout(self, dim=3, scale=np.sqrt(self.order()))
  13. middle = np.average(pos.values(), axis=0)
  14. pos = {key: value - middle for key, value in pos.items()}
  15. for key, (x, y, z) in pos.items():
  16. self.node[key]["position"] = util.xyz(x, y, z)