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

Skip to content

Commit 639c784

Browse files
greglucasandrew-fennell
authored andcommitted
MNT: Remove keyword arguments to gca()
This removes the deprecated passing of keyword arguments to gca().
1 parent de82eaa commit 639c784

File tree

6 files changed

+20
-122
lines changed

6 files changed

+20
-122
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Keyword arguments to ``gca()`` have been removed
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
There is no replacement.

lib/matplotlib/figure.py

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,7 @@ def sca(self, a):
15091509
self._axobservers.process("_axes_change_event", self)
15101510
return a
15111511

1512-
@_docstring.dedent_interpd
1513-
def gca(self, **kwargs):
1512+
def gca(self):
15141513
"""
15151514
Get the current Axes.
15161515
@@ -1519,25 +1518,9 @@ def gca(self, **kwargs):
15191518
Axes on a Figure, check whether ``figure.axes`` is empty. To test
15201519
whether there is currently a Figure on the pyplot figure stack, check
15211520
whether `.pyplot.get_fignums()` is empty.)
1522-
1523-
The following kwargs are supported for ensuring the returned Axes
1524-
adheres to the given projection etc., and for Axes creation if
1525-
the active Axes does not exist:
1526-
1527-
%(Axes:kwdoc)s
1528-
"""
1529-
if kwargs:
1530-
_api.warn_deprecated(
1531-
"3.4",
1532-
message="Calling gca() with keyword arguments was deprecated "
1533-
"in Matplotlib %(since)s. Starting %(removal)s, gca() will "
1534-
"take no keyword arguments. The gca() function should only be "
1535-
"used to get the current axes, or if no axes exist, create "
1536-
"new axes with default keyword arguments. To create a new "
1537-
"axes with non-default arguments, use plt.axes() or "
1538-
"plt.subplot().")
1521+
"""
15391522
ax = self._axstack.current()
1540-
return ax if ax is not None else self.add_subplot(**kwargs)
1523+
return ax if ax is not None else self.add_subplot()
15411524

15421525
def _gci(self):
15431526
# Helper for `~matplotlib.pyplot.gci`. Do not use elsewhere.

lib/matplotlib/pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,8 +2222,8 @@ def figtext(x, y, s, fontdict=None, **kwargs):
22222222

22232223
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
22242224
@_copy_docstring_and_deprecators(Figure.gca)
2225-
def gca(**kwargs):
2226-
return gcf().gca(**kwargs)
2225+
def gca():
2226+
return gcf().gca()
22272227

22282228

22292229
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.

lib/matplotlib/tests/test_axes.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,42 +2605,10 @@ def _as_mpl_axes(self):
26052605
prj = Polar()
26062606
prj2 = Polar()
26072607
prj2.theta_offset = np.pi
2608-
prj3 = Polar()
26092608

26102609
# testing axes creation with plt.axes
26112610
ax = plt.axes([0, 0, 1, 1], projection=prj)
26122611
assert type(ax) == PolarAxes
2613-
with pytest.warns(
2614-
MatplotlibDeprecationWarning,
2615-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
2616-
ax_via_gca = plt.gca(projection=prj)
2617-
assert ax_via_gca is ax
2618-
plt.close()
2619-
2620-
# testing axes creation with gca
2621-
with pytest.warns(
2622-
MatplotlibDeprecationWarning,
2623-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
2624-
ax = plt.gca(projection=prj)
2625-
assert type(ax) == mpl.axes._subplots.subplot_class_factory(PolarAxes)
2626-
with pytest.warns(
2627-
MatplotlibDeprecationWarning,
2628-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
2629-
ax_via_gca = plt.gca(projection=prj)
2630-
assert ax_via_gca is ax
2631-
# try getting the axes given a different polar projection
2632-
with pytest.warns(
2633-
MatplotlibDeprecationWarning,
2634-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
2635-
ax_via_gca = plt.gca(projection=prj2)
2636-
assert ax_via_gca is ax
2637-
assert ax.get_theta_offset() == 0
2638-
# try getting the axes given an == (not is) polar projection
2639-
with pytest.warns(
2640-
MatplotlibDeprecationWarning,
2641-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
2642-
ax_via_gca = plt.gca(projection=prj3)
2643-
assert ax_via_gca is ax
26442612
plt.close()
26452613

26462614
# testing axes creation with subplot

lib/matplotlib/tests/test_figure.py

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import matplotlib as mpl
1515
from matplotlib import gridspec, rcParams
16-
from matplotlib._api.deprecation import MatplotlibDeprecationWarning
1716
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1817
from matplotlib.axes import Axes
1918
from matplotlib.figure import Figure, FigureBase
@@ -189,62 +188,30 @@ def test_figure_legend():
189188
def test_gca():
190189
fig = plt.figure()
191190

191+
# test that gca() picks up Axes created via add_axes()
192192
ax0 = fig.add_axes([0, 0, 1, 1])
193-
with pytest.warns(
194-
MatplotlibDeprecationWarning,
195-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
196-
assert fig.gca(projection='rectilinear') is ax0
197193
assert fig.gca() is ax0
198194

199-
ax1 = fig.add_axes(rect=[0.1, 0.1, 0.8, 0.8])
200-
with pytest.warns(
201-
MatplotlibDeprecationWarning,
202-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
203-
assert fig.gca(projection='rectilinear') is ax1
195+
# test that gca() picks up Axes created via add_subplot()
196+
ax1 = fig.add_subplot(111)
204197
assert fig.gca() is ax1
205198

206-
ax2 = fig.add_subplot(121, projection='polar')
207-
assert fig.gca() is ax2
208-
with pytest.warns(
209-
MatplotlibDeprecationWarning,
210-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
211-
assert fig.gca(polar=True) is ax2
212-
213-
ax3 = fig.add_subplot(122)
214-
assert fig.gca() is ax3
215-
216-
with pytest.warns(
217-
MatplotlibDeprecationWarning,
218-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
219-
assert fig.gca(polar=True) is ax3
220-
with pytest.warns(
221-
MatplotlibDeprecationWarning,
222-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
223-
assert fig.gca(polar=True) is not ax2
224-
assert fig.gca().get_subplotspec().get_geometry() == (1, 2, 1, 1)
225-
226199
# add_axes on an existing Axes should not change stored order, but will
227200
# make it current.
228201
fig.add_axes(ax0)
229-
assert fig.axes == [ax0, ax1, ax2, ax3]
202+
assert fig.axes == [ax0, ax1]
230203
assert fig.gca() is ax0
231204

205+
# sca() should not change stored order of Axes, which is order added.
206+
fig.sca(ax0)
207+
assert fig.axes == [ax0, ax1]
208+
232209
# add_subplot on an existing Axes should not change stored order, but will
233210
# make it current.
234-
fig.add_subplot(ax2)
235-
assert fig.axes == [ax0, ax1, ax2, ax3]
236-
assert fig.gca() is ax2
237-
238-
fig.sca(ax1)
239-
with pytest.warns(
240-
MatplotlibDeprecationWarning,
241-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
242-
assert fig.gca(projection='rectilinear') is ax1
211+
fig.add_subplot(ax1)
212+
assert fig.axes == [ax0, ax1]
243213
assert fig.gca() is ax1
244214

245-
# sca() should not change stored order of Axes, which is order added.
246-
assert fig.axes == [ax0, ax1, ax2, ax3]
247-
248215

249216
def test_add_subplot_subclass():
250217
fig = plt.figure()

lib/matplotlib/tests/test_pyplot.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def test_subplot_kwarg_collision():
236236
assert ax1 not in plt.gcf().axes
237237

238238

239-
def test_gca_kwargs():
239+
def test_gca():
240240
# plt.gca() returns an existing axes, unless there were no axes.
241241
plt.figure()
242242
ax = plt.gca()
@@ -245,30 +245,6 @@ def test_gca_kwargs():
245245
assert ax1 is ax
246246
plt.close()
247247

248-
# plt.gca() raises a DeprecationWarning if called with kwargs.
249-
plt.figure()
250-
with pytest.warns(
251-
MatplotlibDeprecationWarning,
252-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
253-
ax = plt.gca(projection='polar')
254-
ax1 = plt.gca()
255-
assert ax is not None
256-
assert ax1 is ax
257-
assert ax1.name == 'polar'
258-
plt.close()
259-
260-
# plt.gca() ignores keyword arguments if an Axes already exists.
261-
plt.figure()
262-
ax = plt.gca()
263-
with pytest.warns(
264-
MatplotlibDeprecationWarning,
265-
match=r'Calling gca\(\) with keyword arguments was deprecated'):
266-
ax1 = plt.gca(projection='polar')
267-
assert ax is not None
268-
assert ax1 is ax
269-
assert ax1.name == 'rectilinear'
270-
plt.close()
271-
272248

273249
def test_subplot_projection_reuse():
274250
# create an Axes

0 commit comments

Comments
 (0)