Skip to content

Commit

Permalink
Merge pull request #5892 from julianvmodesto/master
Browse files Browse the repository at this point in the history
Fix gridspec.Gridspec: check ratios for consistency with rows and columns
  • Loading branch information
jenshnielsen committed Jan 24, 2016
1 parent 52877ca commit 308ce5d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 6 additions & 2 deletions lib/matplotlib/gridspec.py
Expand Up @@ -62,20 +62,24 @@ def new_subplotspec(self, loc, rowspan=1, colspan=1):
subplotspec = self[loc1:loc1+rowspan, loc2:loc2+colspan]
return subplotspec


def set_width_ratios(self, width_ratios):
if width_ratios is not None and 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

def get_width_ratios(self):
return self._col_width_ratios

def set_height_ratios(self, height_ratios):
if height_ratios is not None and 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

def get_height_ratios(self):
return self._row_height_ratios


def get_grid_positions(self, fig):
"""
return lists of bottom and top position of rows, left and
Expand Down
20 changes: 19 additions & 1 deletion lib/matplotlib/tests/test_gridspec.py
@@ -1,8 +1,26 @@
import matplotlib.gridspec as gridspec
from nose.tools import assert_equal
from nose.tools import assert_raises, assert_equal


def test_equal():
gs = gridspec.GridSpec(2, 1)
assert_equal(gs[0, 0], gs[0, 0])
assert_equal(gs[:, 0], gs[:, 0])


def test_width_ratios():
"""
Addresses issue #5835.
See at https://github.com/matplotlib/matplotlib/issues/5835.
"""
assert_raises(ValueError, gridspec.GridSpec,
1, 1, width_ratios=[2, 1, 3])


def test_height_ratios():
"""
Addresses issue #5835.
See at https://github.com/matplotlib/matplotlib/issues/5835.
"""
assert_raises(ValueError, gridspec.GridSpec,
1, 1, height_ratios=[2, 1, 3])

0 comments on commit 308ce5d

Please sign in to comment.