Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5eea274

Browse filesBrowse files
authored
Merge pull request #17164 from QuLogic/add_axes-rect
Fix Figure.add_axes(rect=...).
2 parents 5e21d05 + 085554e commit 5eea274
Copy full SHA for 5eea274

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+5Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_figure.py
+8-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.