Skip to content

Commit a2f73b1

Browse files
committed
TST and DOC
1 parent 2d4a162 commit a2f73b1

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

lib/matplotlib/figure.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1264,13 +1264,16 @@ def add_subplot(self, *args, **kwargs):
12641264
12651265
Parameters
12661266
----------
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)
12681268
The position of the subplot described by one of
12691269
12701270
- Three integers (*nrows*, *ncols*, *index*). The subplot will
12711271
take the *index* position on a grid with *nrows* rows and
12721272
*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+
sepcifying 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.
12741277
- A 3-digit integer. The digits are interpreted as if given
12751278
separately as three single-digit integers, i.e.
12761279
``fig.add_subplot(235)`` is the same as
@@ -1378,18 +1381,18 @@ def add_subplot(self, *args, **kwargs):
13781381
'position specification.')
13791382
elif nargs == 3:
13801383
newarg = [None] * 3
1381-
message=("Passing non-integers as three-element "
1382-
"position specification is deprecated since "
1383-
"%(since)s and will be removed %(removal)s.")
1384+
message = ("Passing non-integers as three-element "
1385+
"position specification is deprecated since "
1386+
"%(since)s and will be removed %(removal)s.")
13841387
for nn, arg in enumerate(args[:2]):
13851388
if not isinstance(arg, Integral):
1386-
cbook.warn_deprecated("3.3", message)
1389+
cbook.warn_deprecated("3.3", message=message)
13871390
newarg[nn] = int(arg)
13881391
if isinstance(args[2], tuple):
13891392
# start/stop two-tuple is allowed...
13901393
for arg in args[2]:
13911394
if not isinstance(arg, Integral):
1392-
cbook.warn_deprecated("3.3", message)
1395+
cbook.warn_deprecated("3.3", message=mesage)
13931396
newarg[nn] = (int(args[0]), int(args[1]))
13941397
else:
13951398
newarg[nn] = int(arg)

lib/matplotlib/tests/test_figure.py

+8
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,11 @@ def test_removed_axis():
533533
fig, axs = plt.subplots(2, sharex=True)
534534
axs[0].remove()
535535
fig.canvas.draw()
536+
537+
538+
def test_add_subplot_twotuple():
539+
fig = plt.figure()
540+
ax = fig.add_subplot(3, 4, 1)
541+
ax2 = fig.add_subplot(3, 2, (3, 5))
542+
assert ax2.get_subplotspec().rowspan == range(1, 3)
543+
assert ax2.get_subplotspec().colspan == range(0, 1)

0 commit comments

Comments
 (0)