@@ -410,7 +410,7 @@ def __init__(self, gridspec, num1, num2=None):
410410 """
411411 The subplot will occupy the num1-th cell of the given
412412 gridspec. If num2 is provided, the subplot will span between
413- num1-th cell and num2-th cell.
413+ num1-th cell and num2-th cell *inclusive* .
414414
415415 The index starts from 0.
416416 """
@@ -430,6 +430,17 @@ def __init__(self, gridspec, num1, num2=None):
430430 else :
431431 self ._layoutbox = None
432432
433+ # num2 is a property only to handle the case where it is None and someone
434+ # mutates num1.
435+
436+ @property
437+ def num2 (self ):
438+ return self .num1 if self ._num2 is None else self ._num2
439+
440+ @num2 .setter
441+ def num2 (self , value ):
442+ self ._num2 = value
443+
433444 def __getstate__ (self ):
434445 state = self .__dict__
435446 try :
@@ -464,21 +475,15 @@ def get_rows_columns(self):
464475 gridspec = self .get_gridspec ()
465476 nrows , ncols = gridspec .get_geometry ()
466477 row_start , col_start = divmod (self .num1 , ncols )
467- if self .num2 is not None :
468- row_stop , col_stop = divmod (self .num2 , ncols )
469- else :
470- row_stop = row_start
471- col_stop = col_start
478+ row_stop , col_stop = divmod (self .num2 , ncols )
472479 return nrows , ncols , row_start , row_stop , col_start , col_stop
473480
474481 def get_position (self , figure , return_all = False ):
475482 """Update the subplot position from ``figure.subplotpars``.
476483 """
477484 gridspec = self .get_gridspec ()
478485 nrows , ncols = gridspec .get_geometry ()
479- rows , cols = np .unravel_index (
480- [self .num1 ] if self .num2 is None else [self .num1 , self .num2 ],
481- (nrows , ncols ))
486+ rows , cols = np .unravel_index ([self .num1 , self .num2 ], (nrows , ncols ))
482487 fig_bottoms , fig_tops , fig_lefts , fig_rights = \
483488 gridspec .get_grid_positions (figure )
484489
0 commit comments