@@ -56,9 +56,9 @@ def __init__(self, nrows, ncols, height_ratios=None, width_ratios=None):
5656
5757 def __repr__ (self ):
5858 height_arg = (', height_ratios=%r' % (self ._row_height_ratios ,)
59- if self ._row_height_ratios is not None else '' )
59+ if len ( set ( self ._row_height_ratios )) != 1 else '' )
6060 width_arg = (', width_ratios=%r' % (self ._col_width_ratios ,)
61- if self ._col_width_ratios is not None else '' )
61+ if len ( set ( self ._col_width_ratios )) != 1 else '' )
6262 return '{clsname}({nrows}, {ncols}{optionals})' .format (
6363 clsname = self .__class__ .__name__ ,
6464 nrows = self ._nrows ,
@@ -104,7 +104,9 @@ def set_width_ratios(self, width_ratios):
104104 *width_ratios* must be of length *ncols*. Each column gets a relative
105105 width of ``width_ratios[i] / sum(width_ratios)``.
106106 """
107- if width_ratios is not None and len (width_ratios ) != self ._ncols :
107+ if width_ratios is None :
108+ width_ratios = [1 ] * self ._ncols
109+ elif len (width_ratios ) != self ._ncols :
108110 raise ValueError ('Expected the given number of width ratios to '
109111 'match the number of columns of the grid' )
110112 self ._col_width_ratios = width_ratios
@@ -124,7 +126,9 @@ def set_height_ratios(self, height_ratios):
124126 *height_ratios* must be of length *nrows*. Each row gets a relative
125127 height of ``height_ratios[i] / sum(height_ratios)``.
126128 """
127- if height_ratios is not None and len (height_ratios ) != self ._nrows :
129+ if height_ratios is None :
130+ height_ratios = [1 ] * self ._nrows
131+ elif len (height_ratios ) != self ._nrows :
128132 raise ValueError ('Expected the given number of height ratios to '
129133 'match the number of rows of the grid' )
130134 self ._row_height_ratios = height_ratios
@@ -181,22 +185,16 @@ def get_grid_positions(self, fig, raw=False):
181185 # calculate accumulated heights of columns
182186 cell_h = tot_height / (nrows + hspace * (nrows - 1 ))
183187 sep_h = hspace * cell_h
184- if self ._row_height_ratios is not None :
185- norm = cell_h * nrows / sum (self ._row_height_ratios )
186- cell_heights = [r * norm for r in self ._row_height_ratios ]
187- else :
188- cell_heights = [cell_h ] * nrows
188+ norm = cell_h * nrows / sum (self ._row_height_ratios )
189+ cell_heights = [r * norm for r in self ._row_height_ratios ]
189190 sep_heights = [0 ] + ([sep_h ] * (nrows - 1 ))
190191 cell_hs = np .cumsum (np .column_stack ([sep_heights , cell_heights ]).flat )
191192
192193 # calculate accumulated widths of rows
193194 cell_w = tot_width / (ncols + wspace * (ncols - 1 ))
194195 sep_w = wspace * cell_w
195- if self ._col_width_ratios is not None :
196- norm = cell_w * ncols / sum (self ._col_width_ratios )
197- cell_widths = [r * norm for r in self ._col_width_ratios ]
198- else :
199- cell_widths = [cell_w ] * ncols
196+ norm = cell_w * ncols / sum (self ._col_width_ratios )
197+ cell_widths = [r * norm for r in self ._col_width_ratios ]
200198 sep_widths = [0 ] + ([sep_w ] * (ncols - 1 ))
201199 cell_ws = np .cumsum (np .column_stack ([sep_widths , cell_widths ]).flat )
202200
0 commit comments