77
88class DrawEmbedding ():
99
10+ def init_figure (self ):
11+ self .fig = plt .figure ()
12+ plt .subplots_adjust (left = 0.0 , right = 1.0 ,
13+ bottom = 0.0 , top = 1.0 ,
14+ wspace = 0.1 , hspace = 0.1 )
15+
1016 def __init__ (self , m , n , t ):
1117 self .total_steps = 0
1218
@@ -22,13 +28,9 @@ def __init__(self, m, n, t):
2228 self .px = 1 / plt .rcParams ['figure.dpi' ] # pixel in inches
2329 plt .rcParams .update ({'axes.titlesize' : 24 })
2430
25- # Init figure
26- self .fig = plt .figure ()
27- plt .subplots_adjust (left = 0.0 , right = 1.0 ,
28- bottom = 0.0 , top = 1.0 ,
29- wspace = 0.1 , hspace = 0.1 )
30-
3131 self .col = 0
32+ self .m = m
33+ self .n = n
3234
3335 self .init_chimera_graph (m , n , t )
3436
@@ -49,7 +51,7 @@ def draw_chimera_graph(self):
4951
5052 # Labels
5153 # Shift labels
52- pos_labels = {node : [pos [0 ] - 0.025 , pos [1 ]]
54+ pos_labels = {node : [pos [0 ] - 0.020 , pos [1 ]]
5355 for (node , pos ) in self .pos_chimera .items ()}
5456 nx .draw_networkx_labels (self .chimera_G ,
5557 pos = pos_labels ,
@@ -143,31 +145,31 @@ def show_embedding(self):
143145
144146 def draw_whole_embedding_step (self , nodes : set [int ], edges : set [tuple [int , int , int ]],
145147 mapping_G_to_H , title = '' ):
146- ax = self .construct_subplot_to_the_right ()
147- ax . set_title (title )
148+ self .init_figure ()
149+ self . fig . suptitle (title , fontsize = 20 )
148150 self .draw_chimera_and_embedding (nodes , edges , mapping_G_to_H )
149151 self .total_steps += 1
150152
151- def construct_subplot_to_the_right (self ) -> Axes :
152- """Constructs a new subplot to the right."""
153- self .col += 1
154- gs = gridspec .GridSpec (1 , self .col )
153+ # def construct_subplot_to_the_right(self) -> Axes:
154+ # """Constructs a new subplot to the right."""
155+ # self.col += 1
156+ # gs = gridspec.GridSpec(1, self.col)
155157
156- # Reposition subplots
157- for i , ax in enumerate (self .fig .axes ):
158- # ax.set_position(gs[i, 0].get_position(self.fig))
159- ax .set_subplotspec (gs [0 , i ])
158+ # # Reposition subplots
159+ # for i, ax in enumerate(self.fig.axes):
160+ # # ax.set_position(gs[i, 0].get_position(self.fig))
161+ # ax.set_subplotspec(gs[0, i])
160162
161- # Add new subplot
162- ax = self .fig .add_subplot (gs [0 , self .col - 1 ])
163- ax .set_position (gs [0 , self .col - 1 ].get_position (self .fig ))
163+ # # Add new subplot
164+ # ax = self.fig.add_subplot(gs[0, self.col-1])
165+ # ax.set_position(gs[0, self.col-1].get_position(self.fig))
164166
165- return ax
167+ # return ax
166168
167169 def save_and_clear (self , path ):
168- self .fig .set_size_inches (self .total_steps * 1000 * self . px , 800 * self .px )
170+ self .fig .set_size_inches (self .m * 3 , self .n * 3 )
169171 self .fig .savefig (path , bbox_inches = 'tight' )
170- plt .clf ( )
172+ plt .close ( self . fig )
171173
172174
173175def change_brightness (color , amount = 1 ):
0 commit comments