8000 Fix Figure.add_axes(rect=...). · matplotlib/matplotlib@085554e · GitHub
[go: up one dir, main page]

Skip to content

Commit 085554e

Browse files
committed
Fix Figure.add_axes(rect=...).
This makes it behave as if the signature was actually `add_axes(rect, **kwargs)` instead of `*args`.
1 parent 30d1396 commit 085554e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,11 @@ def add_axes(self, *args, **kwargs):
12111211
"deprecated. You may want to use add_subplot() "
12121212
"instead.")
12131213
return
1214+
elif 'rect' in kwargs:
1215+
if len(args):
1216+
raise TypeError(
1217+
"add_axes() got multiple values for argument 'rect'")
1218+
args = (kwargs.pop('rect'), )
12141219

12151220
# shortcut the projection "key" modifications later on, if an axes
12161221
# with the exact args/kwargs exists, return it immediately.

lib/matplotlib/tests/test_figure.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ def test_gca():
150150
# empty call to add_axes() will throw deprecation warning
151151
assert fig.add_axes() is None
152152

153-
ax1 = fig.add_axes([0, 0, 1, 1])
153+
ax0 = fig.add_axes([0, 0, 1, 1])
154+
assert fig.gca(projection='rectilinear') is ax0
155+
assert fig.gca() is ax0
156+
157+
ax1 = fig.add_axes(rect=[0.1, 0.1, 0.8, 0.8])
154158
assert fig.gca(projection='rectilinear') is ax1
155159
assert fig.gca() is ax1
156160

@@ -387,6 +391,9 @@ def test_invalid_figure_add_axes():
387391
with pytest.raises(ValueError):
388392
fig.add_axes((.1, .1, .5, np.nan))
389393

394+
with pytest.raises(TypeError, match="multiple values for argument 'rect'"):
395+
fig.add_axes([0, 0, 1, 1], rect=[0, 0, 1, 1])
396+
390397

391398
def test_subplots_shareax_loglabels():
392399
fig, axs = plt.subplots(2, 2, sharex=True, sharey=True, squeeze=False)

0 commit comments

Comments
 (0)
0