diff --git a/lib/matplotlib/_constrained_layout.py b/lib/matplotlib/_constrained_layout.py index 6d13a850bc43..dc00b6c50e05 100644 --- a/lib/matplotlib/_constrained_layout.py +++ b/lib/matplotlib/_constrained_layout.py @@ -314,10 +314,6 @@ def _align_spines(fig, gs): nrows, ncols = gs.get_geometry() width_ratios = gs.get_width_ratios() height_ratios = gs.get_height_ratios() - if width_ratios is None: - width_ratios = np.ones(ncols) - if height_ratios is None: - height_ratios = np.ones(nrows) # get axes in this gridspec.... axs = [ax for ax in fig.axes diff --git a/lib/matplotlib/_layoutbox.py b/lib/matplotlib/_layoutbox.py index 0afa2e4829f2..2c61890e6bce 100644 --- a/lib/matplotlib/_layoutbox.py +++ b/lib/matplotlib/_layoutbox.py @@ -499,38 +499,22 @@ def vpack(boxes, padding=0, strength='strong'): boxes[i].solver.addConstraint(c | strength) -def match_heights(boxes, height_ratios=None, strength='medium'): +def match_heights(boxes, height_ratios, strength='medium'): """Stack LayoutBox instances from top to bottom.""" - - if height_ratios is None: - height_ratios = np.ones(len(boxes)) for i in range(1, len(boxes)): c = (boxes[i-1].height == boxes[i].height*height_ratios[i-1]/height_ratios[i]) boxes[i].solver.addConstraint(c | strength) -def match_widths(boxes, width_ratios=None, strength='medium'): +def match_widths(boxes, width_ratios, strength='medium'): """Stack LayoutBox instances from top to bottom.""" - - if width_ratios is None: - width_ratios = np.ones(len(boxes)) for i in range(1, len(boxes)): c = (boxes[i-1].width == boxes[i].width*width_ratios[i-1]/width_ratios[i]) boxes[i].solver.addConstraint(c | strength) -def vstackeq(boxes, padding=0, height_ratios=None): - vstack(boxes, padding=padding) - match_heights(boxes, height_ratios=height_ratios) - - -def hstackeq(boxes, padding=0, width_ratios=None): - hstack(boxes, padding=padding) - match_widths(boxes, width_ratios=width_ratios) - - def align(boxes, attr, strength='strong'): cons = [] for box in boxes[1:]: diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index cd07136beb80..087f1c791efe 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -56,9 +56,9 @@ def __init__(self, nrows, ncols, height_ratios=None, width_ratios=None): def __repr__(self): height_arg = (', height_ratios=%r' % (self._row_height_ratios,) - if self._row_height_ratios is not None else '') + if len(set(self._row_height_ratios)) != 1 else '') width_arg = (', width_ratios=%r' % (self._col_width_ratios,) - if self._col_width_ratios is not None else '') + if len(set(self._col_width_ratios)) != 1 else '') return '{clsname}({nrows}, {ncols}{optionals})'.format( clsname=self.__class__.__name__, nrows=self._nrows, @@ -104,7 +104,9 @@ def set_width_ratios(self, width_ratios): *width_ratios* must be of length *ncols*. Each column gets a relative width of ``width_ratios[i] / sum(width_ratios)``. """ - if width_ratios is not None and len(width_ratios) != self._ncols: + if width_ratios is None: + width_ratios = [1] * self._ncols + elif len(width_ratios) != self._ncols: raise ValueError('Expected the given number of width ratios to ' 'match the number of columns of the grid') self._col_width_ratios = width_ratios @@ -124,7 +126,9 @@ def set_height_ratios(self, height_ratios): *height_ratios* must be of length *nrows*. Each row gets a relative height of ``height_ratios[i] / sum(height_ratios)``. """ - if height_ratios is not None and len(height_ratios) != self._nrows: + if height_ratios is None: + height_ratios = [1] * self._nrows + elif len(height_ratios) != self._nrows: raise ValueError('Expected the given number of height ratios to ' 'match the number of rows of the grid') self._row_height_ratios = height_ratios @@ -181,22 +185,16 @@ def get_grid_positions(self, fig, raw=False): # calculate accumulated heights of columns cell_h = tot_height / (nrows + hspace*(nrows-1)) sep_h = hspace * cell_h - if self._row_height_ratios is not None: - norm = cell_h * nrows / sum(self._row_height_ratios) - cell_heights = [r * norm for r in self._row_height_ratios] - else: - cell_heights = [cell_h] * nrows + norm = cell_h * nrows / sum(self._row_height_ratios) + cell_heights = [r * norm for r in self._row_height_ratios] sep_heights = [0] + ([sep_h] * (nrows-1)) cell_hs = np.cumsum(np.column_stack([sep_heights, cell_heights]).flat) # calculate accumulated widths of rows cell_w = tot_width / (ncols + wspace*(ncols-1)) sep_w = wspace * cell_w - if self._col_width_ratios is not None: - norm = cell_w * ncols / sum(self._col_width_ratios) - cell_widths = [r * norm for r in self._col_width_ratios] - else: - cell_widths = [cell_w] * ncols + norm = cell_w * ncols / sum(self._col_width_ratios) + cell_widths = [r * norm for r in self._col_width_ratios] sep_widths = [0] + ([sep_w] * (ncols-1)) cell_ws = np.cumsum(np.column_stack([sep_widths, cell_widths]).flat) diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index f3e3d517a88a..31f0dafe4dec 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -40,8 +40,8 @@ def test_simple(): pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL) -@image_comparison(['multi_pickle.png'], remove_text=True, style='mpl20', - tol=0 if platform.machine() == 'x86_64' else 0.082) +@image_comparison( + ['multi_pickle.png'], remove_text=True, style='mpl20', tol=0.082) def test_complete(): # Remove this line when this test image is regenerated. plt.rcParams['pcolormesh.snap'] = False diff --git a/lib/matplotlib/tests/test_tightlayout.py b/lib/matplotlib/tests/test_tightlayout.py index 9ad2e0a9a080..cc928005c15b 100644 --- a/lib/matplotlib/tests/test_tightlayout.py +++ b/lib/matplotlib/tests/test_tightlayout.py @@ -50,7 +50,8 @@ def test_tight_layout3(): plt.tight_layout() -@image_comparison(['tight_layout4'], freetype_version=('2.5.5', '2.6.1')) +@image_comparison(['tight_layout4'], freetype_version=('2.5.5', '2.6.1'), + tol=0.015) def test_tight_layout4(): """Test tight_layout for subplot2grid.""" ax1 = plt.subplot2grid((3, 3), (0, 0))