@@ -56,9 +56,9 @@ def __init__(self, nrows, ncols, height_ratios=None, width_ratios=None):
56
56
57
57
def __repr__ (self ):
58
58
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 '' )
60
60
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 '' )
62
62
return '{clsname}({nrows}, {ncols}{optionals})' .format (
63
63
clsname = self .__class__ .__name__ ,
64
64
nrows = self ._nrows ,
@@ -104,7 +104,9 @@ def set_width_ratios(self, width_ratios):
104
104
*width_ratios* must be of length *ncols*. Each column gets a relative
105
105
width of ``width_ratios[i] / sum(width_ratios)``.
106
106
"""
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 :
108
110
raise ValueError ('Expected the given number of width ratios to '
109
111
'match the number of columns of the grid' )
110
112
self ._col_width_ratios = width_ratios
@@ -124,7 +126,9 @@ def set_height_ratios(self, height_ratios):
124
126
*height_ratios* must be of length *nrows*. Each row gets a relative
125
127
height of ``height_ratios[i] / sum(height_ratios)``.
126
128
"""
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 :
128
132
raise ValueError ('Expected the given number of height ratios to '
129
133
'match the number of rows of the grid' )
130
134
self ._row_height_ratios = height_ratios
@@ -181,22 +185,16 @@ def get_grid_positions(self, fig, raw=False):
181
185
# calculate accumulated heights of columns
182
186
cell_h = tot_height / (nrows + hspace * (nrows - 1 ))
183
187
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 ]
189
190
sep_heights = [0 ] + ([sep_h ] * (nrows - 1 ))
190
191
cell_hs = np .cumsum (np .column_stack ([sep_heights , cell_heights ]).flat )
191
192
192
193
# calculate accumulated widths of rows
193
194
cell_w = tot_width / (ncols + wspace * (ncols - 1 ))
194
195
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 ]
200
198
sep_widths = [0 ] + ([sep_w ] * (ncols - 1 ))
201
199
cell_ws = np .cumsum (np .column_stack ([sep_widths , cell_widths ]).flat )
202
200
0 commit comments