Skip to content

Commit 3783bf3

Browse files
Check for consistent height and width ratios
1 parent 02f4cdb commit 3783bf3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/matplotlib/gridspec.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,24 @@ def new_subplotspec(self, loc, rowspan=1, colspan=1):
6262
subplotspec = self[loc1:loc1+rowspan, loc2:loc2+colspan]
6363
return subplotspec
6464

65-
6665
def set_width_ratios(self, width_ratios):
66+
if width_ratios is not None and len(width_ratios) != self._ncols:
67+
raise ValueError('Expected the given number of width ratios to '
68+
'match the number of columns of the grid')
6769
self._col_width_ratios = width_ratios
6870

6971
def get_width_ratios(self):
7072
return self._col_width_ratios
7173

7274
def set_height_ratios(self, height_ratios):
75+
if height_ratios is not None and len(height_ratios) != self._nrows:
76+
raise ValueError('Expected the given number of height ratios to '
77+
'match the number of rows of the grid')
7378
self._row_height_ratios = height_ratios
7479

7580
def get_height_ratios(self):
7681
return self._row_height_ratios
7782

78-
7983
def get_grid_positions(self, fig):
8084
"""
8185
return lists of bottom and top position of rows, left and

lib/matplotlib/tests/test_gridspec.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import matplotlib.gridspec as gridspec
2-
from nose.tools import assert_equal
2+
from nose.tools import assert_raises, assert_equal
33

44

55
def test_equal():
66
gs = gridspec.GridSpec(2, 1)
77
assert_equal(gs[0, 0], gs[0, 0])
88
assert_equal(gs[:, 0], gs[:, 0])
9+
10+
11+
def test_ratios():
12+
assert_raises(ValueError, gridspec.GridSpec,
13+
1, 2, width_ratios=[2, 1, 3], height_ratios=[3, 4])

0 commit comments

Comments
 (0)