@@ -1264,13 +1264,16 @@ def add_subplot(self, *args, **kwargs):
1264
1264
1265
1265
Parameters
1266
1266
----------
1267
- *args, int or (int, int, int) or `SubplotSpec`, default: (1, 1, 1)
1267
+ *args, int, (int, int, *index*), or `SubplotSpec`, default: (1, 1, 1)
1268
1268
The position of the subplot described by one of
1269
1269
1270
1270
- Three integers (*nrows*, *ncols*, *index*). The subplot will
1271
1271
take the *index* position on a grid with *nrows* rows and
1272
1272
*ncols* columns. *index* starts at 1 in the upper left corner
1273
- and increases to the right.
1273
+ and increases to the right. *index* can also be a two-tuple
1274
+ specifying the (*start*, *stop*) indices of the subplot, i.e.,
1275
+ ``fig.add_subplot(3, 1, (1, 2))`` makes a subplot that spans the
1276
+ upper 2/3 of the figure.
1274
1277
- A 3-digit integer. The digits are interpreted as if given
1275
1278
separately as three single-digit integers, i.e.
1276
1279
``fig.add_subplot(235)`` is the same as
@@ -1377,14 +1380,26 @@ def add_subplot(self, *args, **kwargs):
1377
1380
raise TypeError ('Positional arguments are not a valid '
1378
1381
'position specification.' )
1379
1382
elif nargs == 3 :
1380
- for arg in args :
1383
+ newarg = [None ] * 3
1384
+ message = ("Passing non-integers as three-element "
1385
+ "position specification is deprecated since "
1386
+ "%(since)s and will be removed %(removal)s." )
1387
+ for nn , arg in enumerate (args [:2 ]):
1381
1388
if not isinstance (arg , Integral ):
1382
- cbook .warn_deprecated (
1383
- "3.3" ,
1384
- message = "Passing non-integers as three-element "
1385
- "position specification is deprecated since "
1386
- "%(since)s and will be removed %(removal)s." )
1387
- args = tuple (map (int , args ))
1389
+ cbook .warn_deprecated ("3.3" , message = message )
1390
+ newarg [nn ] = int (arg )
1391
+ args2 = args [2 ]
1392
+ if isinstance (args2 , tuple ) and len (args2 ) == 2 :
1393
+ # start/stop two-tuple is allowed...
1394
+ for arg in args2 :
1395
+ if not isinstance (arg , Integral ):
1396
+ cbook .warn_deprecated ("3.3" , message = message )
1397
+ newarg [2 ] = (int (args2 [0 ]), int (args2 [1 ]))
1398
+ else :
1399
+ if not isinstance (args2 , Integral ):
1400
+ cbook .warn_deprecated ("3.3" , message = message )
1401
+ newarg [2 ] = int (args2 )
1402
+ args = tuple (newarg )
1388
1403
else :
1389
1404
raise TypeError (f'add_subplot() takes 1 or 3 positional arguments '
1390
1405
f'but { nargs } were given' )
0 commit comments