Skip to content

Commit 1e45f00

Browse files
committed
[3032390] subplot: more robust argument handling, consistent with 0.99.3
svn path=/branches/v1_0_maint/; revision=8579
1 parent b065107 commit 1e45f00

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

lib/matplotlib/axes.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -8295,6 +8295,7 @@ def __init__(self, fig, *args, **kwargs):
82958295
being created. *plotNum* starts at 1 in the upper left
82968296
corner and increases to the right.
82978297
8298+
82988299
If *numRows* <= *numCols* <= *plotNum* < 10, *args* can be the
82998300
decimal integer *numRows* * 100 + *numCols* * 10 + *plotNum*.
83008301
"""
@@ -8304,24 +8305,27 @@ def __init__(self, fig, *args, **kwargs):
83048305
if len(args) == 1:
83058306
if isinstance(args[0], SubplotSpec):
83068307
self._subplotspec = args[0]
8307-
83088308
else:
8309-
s = str(args[0])
8310-
if len(s) != 3:
8311-
raise ValueError('Argument to subplot must be a 3 digits long')
8312-
rows, cols, num = map(int, s)
8309+
try:
8310+
s = str(int(args[0]))
8311+
rows, cols, num = map(int, s)
8312+
except ValueError:
8313+
raise ValueError(
8314+
'Single argument to subplot must be a 3-digit integer')
83138315
self._subplotspec = GridSpec(rows, cols)[num-1]
83148316
# num - 1 for converting from MATLAB to python indexing
83158317
elif len(args)==3:
83168318
rows, cols, num = args
8319+
rows = int(rows)
8320+
cols = int(cols)
83178321
if isinstance(num, tuple) and len(num) == 2:
8322+
num = [int(n) for n in num]
83188323
self._subplotspec = GridSpec(rows, cols)[num[0]-1:num[1]]
83198324
else:
8320-
self._subplotspec = GridSpec(rows, cols)[num-1]
8325+
self._subplotspec = GridSpec(rows, cols)[int(num)-1]
83218326
# num - 1 for converting from MATLAB to python indexing
83228327
else:
8323-
raise ValueError( 'Illegal argument to subplot')
8324-
8328+
raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
83258329

83268330
self.update_params()
83278331

lib/matplotlib/gridspec.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def set_height_ratios(self, height_ratios):
7070
def get_height_ratios(self):
7171
return self._row_height_ratios
7272

73-
73+
7474
def get_grid_positions(self, fig):
7575
"""
7676
return lists of bottom and top position of rows, left and
@@ -116,7 +116,7 @@ def get_grid_positions(self, fig):
116116

117117
sepWidths = [0] + ([sepW] * (ncols-1))
118118
cellWs = np.add.accumulate(np.ravel(zip(sepWidths, cellWidths)))
119-
119+
120120

121121

122122
figTops = [top - cellHs[2*rowNum] for rowNum in range(nrows)]
@@ -126,7 +126,7 @@ def get_grid_positions(self, fig):
126126

127127

128128
return figBottoms, figTops, figLefts, figRights
129-
129+
130130

131131
def __getitem__(self, key):
132132
"""
@@ -287,7 +287,7 @@ def __init__(self, nrows, ncols,
287287

288288
def get_subplot_params(self, fig=None):
289289
"""
290-
return a dictionary of subplot layout parameters.
290+
return a dictionary of subplot layout parameters.
291291
"""
292292

293293
if fig is None:
@@ -324,7 +324,7 @@ class SubplotSpec(object):
324324
"""
325325
specifies the location of the subplot in the given *GridSpec*.
326326
"""
327-
327+
328328
def __init__(self, gridspec, num1, num2=None):
329329
"""
330330
The subplot will occupy the num1-th cell of the given

0 commit comments

Comments
 (0)