diff --git a/doc/api/next_api_changes/deprecated_empty_add_axes.rst b/doc/api/next_api_changes/deprecated_empty_add_axes.rst new file mode 100644 index 000000000000..beefbf79ad02 --- /dev/null +++ b/doc/api/next_api_changes/deprecated_empty_add_axes.rst @@ -0,0 +1,5 @@ +Deprecations +```````````` + +Calling ``fig.add_axes()`` with no arguments currently return None, +will raise an error in the future diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 46e3b755271b..d120105b0b0a 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1221,6 +1221,11 @@ def add_axes(self, *args, **kwargs): """ if not len(args): + cbook.warn_deprecated( + "3.3", + message="Calling add_axes() without argument is " + "deprecated. You may want to use add_suplot() " + "instead.") return # shortcut the projection "key" modifications later on, if an axes diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index a9e8dfade9dc..52befc23f14a 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -141,6 +141,10 @@ def test_figure_legend(): def test_gca(): fig = plt.figure() + with pytest.warns(UserWarning): + # empty call to add_axes() will throw deprecation warning + assert fig.add_axes() is None + ax1 = fig.add_axes([0, 0, 1, 1]) assert fig.gca(projection='rectilinear') is ax1 assert fig.gca() is ax1