@@ -1265,16 +1265,27 @@ def add_subplot(self, *args, **kwargs):
1265
1265
1266
1266
Parameters
1267
1267
----------
1268
+ <<<<<<< HEAD
1268
1269
*args : int, (int, int, *index*), or `.SubplotSpec`, default: (1, 1, 1)
1270
+ =======
1271
+ *args, int, (int, int, *index*), or `SubplotSpec`, default: (1, 1, 1)
1272
+ >>>>>>> FIX: allow start-stop subplot
1269
1273
The position of the subplot described by one of
1270
1274
1271
1275
- Three integers (*nrows*, *ncols*, *index*). The subplot will
1272
1276
take the *index* position on a grid with *nrows* rows and
1273
1277
*ncols* columns. *index* starts at 1 in the upper left corner
1278
+ <<<<<<< HEAD
1274
1279
and increases to the right. *index* can also be a two-tuple
1275
1280
specifying the (*first*, *last*) indices (1-based, and including
1276
1281
*last*) of the subplot, e.g., ``fig.add_subplot(3, 1, (1, 2))``
1277
1282
makes a subplot that spans the upper 2/3 of the figure.
1283
+ =======
1284
+ and increases to the right. *index* can also be a two-tuple
1285
+ specifying the (*start*, *stop*) indices of the subplot, i.e.,
1286
+ ``fig.add_subplot(3, 1, (1, 2))`` makes a subplot that spans the
1287
+ upper 2/3 of the figure.
1288
+ >>>>>>> FIX: allow start-stop subplot
1278
1289
- A 3-digit integer. The digits are interpreted as if given
1279
1290
separately as three single-digit integers, i.e.
1280
1291
``fig.add_subplot(235)`` is the same as
@@ -1366,7 +1377,46 @@ def add_subplot(self, *args, **kwargs):
1366
1377
raise TypeError (
1367
1378
"add_subplot() got an unexpected keyword argument 'figure'" )
1368
1379
1369
- if len (args ) == 1 and isinstance (args [0 ], SubplotBase ):
1380
+ nargs = len (args )
1381
+ if nargs == 0 :
1382
+ args = (1 , 1 , 1 )
1383
+ elif nargs == 1 :
1384
+ if isinstance (args [0 ], Integral ):
1385
+ if not 100 <= args [0 ] <= 999 :
1386
+ raise ValueError (f"Integer subplot specification must be "
1387
+ f"a three-digit number, not { args [0 ]} " )
1388
+ args = tuple (map (int , str (args [0 ])))
1389
+ elif isinstance (args [0 ], (SubplotBase , SubplotSpec )):
1390
+ pass # no further validation or normalization needed
1391
+ else :
1392
+ raise TypeError ('Positional arguments are not a valid '
1393
+ 'position specification.' )
1394
+ elif nargs == 3 :
1395
+ newarg = [None ] * 3
1396
+ message = ("Passing non-integers as three-element "
1397
+ "position specification is deprecated since "
1398
+ "%(since)s and will be removed %(removal)s." )
1399
+ for nn , arg in enumerate (args [:2 ]):
1400
+ if not isinstance (arg , Integral ):
1401
+ cbook .warn_deprecated ("3.3" , message = message )
1402
+ newarg [nn ] = int (arg )
1403
+ args2 = args [2 ]
1404
+ if isinstance (args [2 ], tuple ) and len (args [2 ]) == 2 :
1405
+ # start/stop two-tuple is allowed...
1406
+ for arg in args [2 ]:
1407
+ if not isinstance (arg , Integral ):
1408
+ cbook .warn_deprecated ("3.3" , message = message )
1409
+ newarg [2 ] = (int (args [2 ][0 ]), int (args [2 ][1 ]))
1410
+ else :
1411
+ if not isinstance (args [2 ], Integral ):
1412
+ cbook .warn_deprecated ("3.3" , message = message )
1413
+ newarg [2 ] = int (args [2 ])
1414
+ args = tuple (newarg )
1415
+ else :
1416
+ raise TypeError (f'add_subplot() takes 1 or 3 positional arguments '
1417
+ f'but { nargs } were given' )
1418
+
1419
+ if isinstance (args [0 ], SubplotBase ):
1370
1420
ax = args [0 ]
1371
1421
if ax .get_figure () is not self :
1372
1422
raise ValueError ("The Subplot must have been created in "
0 commit comments