Browse Source

rendering is a bit better

arnaud 2 years ago
parent
commit
e7fa7a22f4
1 changed files with 13 additions and 7 deletions
  1. 13 7
      main.py

+ 13 - 7
main.py

@@ -16,28 +16,34 @@ class Lattice():
     def generate_configuration(self, p):
         nb_edges = len(self.graph.edges())
         config = np.random.binomial(1, p, size=nb_edges)
+        opening = {e: val for e, val in zip(self.graph.edges, config)}
+        nx.set_edge_attributes(self.graph, values=opening, name='is_open')
         return config
 
     def draw(self, config):
         _pos = {(x,y):(x,y) for x,y in self.graph.nodes()}
-        edge_colors = ['white' if config[i]==0 else 'black' for i,e in enumerate(self.graph.edges)]
+
+
+        edge_colors = ['white' if d['is_open']==0 else 'black' for (u, v, d) in self.graph.edges(data=True)]
         options = {
             'pos': _pos,
-            'width':2,
+            'width':1,
             'edge_color':edge_colors,
-            'node_size': 0
+            'node_size': .1,
+            'node_color': 'black',
+            # 'linewidth': 0, 
         }
-        fig = plt.figure(figsize=(20,20))
+        fig = plt.figure(figsize=(30,30))
         nx.draw(
         G=self.graph,
         **options
         )
-
-        plt.savefig('./figures/my_fig.png',dpi=1000)
+        plt.gca().set_aspect('equal')
+        # plt.savefig('./figures/my_fig.png',dpi=1000)
         plt.show()
 
 
 if __name__ == "__main__":
-    lattice = Lattice(10)
+    lattice = Lattice(50)
     latt_conf = lattice.generate_configuration(.2)
     lattice.draw(latt_conf)