@@ -384,7 +384,6 @@ def show(self, warn=True):
384
384
AttributeError.
385
385
386
386
.. warning::
387
-
388
387
This does not manage an GUI event loop. Consequently, the figure
389
388
may only be shown briefly or not shown at all if you or your
390
389
environment are not managing an event loop.
@@ -1265,16 +1264,13 @@ def add_subplot(self, *args, **kwargs):
1265
1264
1266
1265
Parameters
1267
1266
----------
1268
- *args : int, (int, int, *index*), or `SubplotSpec`, default: (1, 1, 1)
1267
+ *args, int or (int, int, int) or `SubplotSpec`, default: (1, 1, 1)
1269
1268
The position of the subplot described by one of
1270
1269
1271
1270
- Three integers (*nrows*, *ncols*, *index*). The subplot will
1272
1271
take the *index* position on a grid with *nrows* rows and
1273
1272
*ncols* columns. *index* starts at 1 in the upper left corner
1274
- and increases to the right. *index* can also be a two-tuple
1275
- specifying the (*start*, *stop*) indices of the subplot, i.e.,
1276
- ``fig.add_subplot(3, 1, (1, 2))`` makes a subplot that spans the
1277
- upper 2/3 of the figure.
1273
+ and increases to the right.
1278
1274
- A 3-digit integer. The digits are interpreted as if given
1279
1275
separately as three single-digit integers, i.e.
1280
1276
``fig.add_subplot(235)`` is the same as
@@ -1381,26 +1377,14 @@ def add_subplot(self, *args, **kwargs):
1381
1377
raise TypeError ('Positional arguments are not a valid '
1382
1378
'position specification.' )
1383
1379
elif nargs == 3 :
1384
- newarg = [None ] * 3
1385
- message = ("Passing non-integers as three-element "
1386
- "position specification is deprecated since "
1387
- "%(since)s and will be removed %(removal)s." )
1388
- for nn , arg in enumerate (args [:2 ]):
1380
+ for arg in args :
1389
1381
if not isinstance (arg , Integral ):
1390
- cbook .warn_deprecated ("3.3" , message = message )
1391
- newarg [nn ] = int (arg )
1392
- args2 = args [2 ]
1393
- if isinstance (args [2 ], tuple ) and len (args [2 ]) == 2 :
1394
- # start/stop two-tuple is allowed...
1395
- for arg in args [2 ]:
1396
- if not isinstance (arg , Integral ):
1397
- cbook .warn_deprecated ("3.3" , message = message )
1398
- newarg [2 ] = (int (args [2 ][0 ]), int (args [2 ][1 ]))
1399
- else :
1400
- if not isinstance (args [2 ], Integral ):
1401
- cbook .warn_deprecated ("3.3" , message = message )
1402
- newarg [2 ] = int (args [2 ])
1403
- args = tuple (newarg )
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 ))
1404
1388
else :
1405
1389
raise TypeError (f'add_subplot() takes 1 or 3 positional arguments '
1406
1390
f'but { nargs } were given' )
@@ -1413,19 +1397,13 @@ def add_subplot(self, *args, **kwargs):
1413
1397
# make a key for the subplot (which includes the axes object id
1414
1398
# in the hash)
1415
1399
key = self ._make_key (* args , ** kwargs )
1416
-
1417
1400
else :
1418
- if not args :
1419
- args = (1 , 1 , 1 )
1420
- # Normalize correct ijk values to (i, j, k) here so that
1421
- # add_subplot(111) == add_subplot(1, 1, 1). Invalid values will
1422
- # trigger errors later (via SubplotSpec._from_subplot_args).
1423
- if (len (args ) == 1 and isinstance (args [0 ], Integral )
1424
- and 100 <= args [0 ] <= 999 ):
1425
- args = tuple (map (int , str (args [0 ])))
1426
1401
projection_class , kwargs , key = \
1427
1402
self ._process_projection_requirements (* args , ** kwargs )
1428
- ax = self ._axstack .get (key ) # search axes with this key in stack
1403
+
1404
+ # try to find the axes with this key in the stack
1405
+ ax = self ._axstack .get (key )
1406
+
1429
1407
if ax is not None :
1430
1408
if isinstance (ax , projection_class ):
1431
1409
# the axes already existed, so set it as active & return
@@ -1438,6 +1416,7 @@ def add_subplot(self, *args, **kwargs):
1438
1416
# Without this, add_subplot would be simpler and
1439
1417
# more similar to add_axes.
1440
1418
self ._axstack .remove (ax )
1419
+
1441
1420
ax = subplot_class_factory (projection_class )(self , * args , ** kwargs )
1442
1421
1443
1422
return self ._add_axes_internal (key , ax )
0 commit comments