@@ -49,9 +49,9 @@ def __init__(self, nrows, ncols, height_ratios=None, width_ratios=None):
49
49
50
50
def __repr__ (self ):
51
51
height_arg = (', height_ratios=%r' % (self ._row_height_ratios ,)
52
- if self ._row_height_ratios is not None else '' )
52
+ if len ( set ( self ._row_height_ratios )) != 1 else '' )
53
53
width_arg = (', width_ratios=%r' % (self ._col_width_ratios ,)
54
- if self ._col_width_ratios is not None else '' )
54
+ if len ( set ( self ._col_width_ratios )) != 1 else '' )
55
55
return '{clsname}({nrows}, {ncols}{optionals})' .format (
56
56
clsname = self .__class__ .__name__ ,
57
57
nrows = self ._nrows ,
@@ -97,7 +97,9 @@ def set_width_ratios(self, width_ratios):
97
97
*width_ratios* must be of length *ncols*. Each column gets a relative
98
98
width of ``width_ratios[i] / sum(width_ratios)``.
99
99
"""
100
- if width_ratios is not None and len (width_ratios ) != self ._ncols :
100
+ if width_ratios is None :
101
+ width_ratios = [1 ] * self ._ncols
102
+ elif len (width_ratios ) != self ._ncols :
101
103
raise ValueError ('Expected the given number of width ratios to '
102
104
'match the number of columns of the grid' )
103
105
self ._col_width_ratios = width_ratios
@@ -117,7 +119,9 @@ def set_height_ratios(self, height_ratios):
117
119
*height_ratios* must be of length *nrows*. Each row gets a relative
118
120
height of ``height_ratios[i] / sum(height_ratios)``.
119
121
"""
120
- if height_ratios is not None and len (height_ratios ) != self ._nrows :
122
+ if height_ratios is None :
123
+ height_ratios = [1 ] * self ._nrows
124
+ elif len (height_ratios ) != self ._nrows :
121
125
raise ValueError ('Expected the given number of height ratios to '
122
126
'match the number of rows of the grid' )
123
127
self ._row_height_ratios = height_ratios
@@ -174,22 +178,16 @@ def get_grid_positions(self, fig, raw=False):
174
178
# calculate accumulated heights of columns
175
179
cell_h = tot_height / (nrows + hspace * (nrows - 1 ))
176
180
sep_h = hspace * cell_h
177
- if self ._row_height_ratios is not None :
178
- norm = cell_h * nrows / sum (self ._row_height_ratios )
179
- cell_heights = [r * norm for r in self ._row_height_ratios ]
180
- else :
181
- cell_heights = [cell_h ] * nrows
181
+ norm = cell_h * nrows / sum (self ._row_height_ratios )
182
+ cell_heights = [r * norm for r in self ._row_height_ratios ]
182
183
sep_heights = [0 ] + ([sep_h ] * (nrows - 1 ))
183
184
cell_hs = np .cumsum (np .column_stack ([sep_heights , cell_heights ]).flat )
184
185
185
186
# calculate accumulated widths of rows
186
187
cell_w = tot_width / (ncols + wspace * (ncols - 1 ))
187
188
sep_w = wspace * cell_w
188
- if self ._col_width_ratios is not None :
189
- norm = cell_w * ncols / sum (self ._col_width_ratios )
190
- cell_widths = [r * norm for r in self ._col_width_ratios ]
191
- else :
192
- cell_widths = [cell_w ] * ncols
189
+ norm = cell_w * ncols / sum (self ._col_width_ratios )
190
+ cell_widths = [r * norm for r in self ._col_width_ratios ]
193
191
sep_widths = [0 ] + ([sep_w ] * (ncols - 1 ))
194
192
cell_ws = np .cumsum (np .column_stack ([sep_widths , cell_widths ]).flat )
195
193
0 commit comments