Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d1d23e

Browse files
authored
Merge pull request #9968 from timhoffm/deprecate-pyplot.axes-ax
API: Deprecate pyplot.axes with an Axes argument
2 parents 375f69a + eafe2a2 commit 1d1d23e

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/api/api_changes/2017-12-10-TH.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Deprecations
2+
````````````
3+
4+
Using `.pyplot.axes` with an `.Axes` as argument is deprecated. This sets
5+
the current axes, i.e. it has the same effect as `.pyplot.sca`. For clarity
6+
``plt.sca(ax)`` should be preferred over ``plt.axes(ax)``.

examples/images_contours_and_fields/multi_image.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
It also illustrates colorbar tick labelling with a multiplier.
99
"""
1010

11-
from matplotlib.pyplot import figure, show, axes, sci
11+
from matplotlib.pyplot import figure, show, sca, sci
1212
from matplotlib import cm, colors
1313
from matplotlib.font_manager import FontProperties
1414
import numpy as np
@@ -77,7 +77,7 @@ def __call__(self, leader):
7777
# We need the following only if we want to run this interactively and
7878
# modify the colormap:
7979

80-
axes(ax[0]) # Return the current axes to the first one,
80+
sca(ax[0]) # Return the current axes to the first one,
8181
sci(images[0]) # because the current image must be in current axes.
8282

8383
show()

lib/matplotlib/pyplot.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
from matplotlib import _pylab_helpers, interactive
3535
from matplotlib.cbook import dedent, silent_list, is_numlike
3636
from matplotlib.cbook import _string_to_bool
37-
from matplotlib.cbook import deprecated
37+
from matplotlib.cbook import deprecated, warn_deprecated
3838
from matplotlib import docstring
3939
from matplotlib.backend_bases import FigureCanvasBase
4040
from matplotlib.figure import Figure, figaspect
@@ -883,6 +883,9 @@ def axes(arg=None, **kwargs):
883883
axes to *arg*. Note: This implicitly changes the current figure to
884884
the parent of *arg*.
885885
886+
.. note:: The use of an Axes as an argument is deprecated and will be
887+
removed in v3.0. Please use `.pyplot.sca` instead.
888+
886889
Other Parameters
887890
----------------
888891
**kwargs :
@@ -927,6 +930,10 @@ def axes(arg=None, **kwargs):
927930
return subplot(111, **kwargs)
928931

929932
if isinstance(arg, Axes):
933+
warn_deprecated("2.2",
934+
message="Using pyplot.axes(ax) with ax an Axes "
935+
"argument is deprecated. Please use "
936+
"pyplot.sca(ax) instead.")
930937
ax = arg
931938
sca(ax)
932939
return ax

0 commit comments

Comments
 (0)