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

Skip to content

Commit 0640e72

Browse files
authored
Merge pull request #24071 from oscargus/gridlabelmode
Deprecate undefined label_mode to Grid
2 parents b6c2738 + 6cf652c commit 0640e72

File tree

3 files changed

+35
-5
lines changed

3 files changed

+35
-5
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Passing undefined *label_mode* to ``Grid``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
... is deprecated. This includes `mpl_toolkits.axes_grid1.axes_grid.Grid`,
5+
`mpl_toolkits.axes_grid1.axes_grid.AxesGrid`, and
6+
`mpl_toolkits.axes_grid1.axes_grid.ImageGrid` as well as the corresponding
7+
classes imported from `mpl_toolkits.axisartist.axes_grid`.
8+
9+
Pass ``label_mode='keep'`` instead to get the previous behavior of not modifying labels.

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,14 @@ def __init__(self, fig,
9999
Whether all axes of a column share their x-axis.
100100
share_y : bool, default: True
101101
Whether all axes of a row share their y-axis.
102-
label_mode : {"L", "1", "all"}, default: "L"
102+
label_mode : {"L", "1", "all", "keep"}, default: "L"
103103
Determines which axes will get tick labels:
104104
105105
- "L": All axes on the left column get vertical tick labels;
106106
all axes on the bottom row get horizontal tick labels.
107107
- "1": Only the bottom left axes is labelled.
108-
- "all": all axes are labelled.
108+
- "all": All axes are labelled.
109+
- "keep": Do not do anything.
109110
110111
axes_class : subclass of `matplotlib.axes.Axes`, default: None
111112
aspect : bool, default: False
@@ -258,13 +259,14 @@ def set_label_mode(self, mode):
258259
259260
Parameters
260261
----------
261-
mode : {"L", "1", "all"}
262+
mode : {"L", "1", "all", "keep"}
262263
The label mode:
263264
264265
- "L": All axes on the left column get vertical tick labels;
265266
all axes on the bottom row get horizontal tick labels.
266267
- "1": Only the bottom left axes is labelled.
267-
- "all": all axes are labelled.
268+
- "all": All axes are labelled.
269+
- "keep": Do not do anything.
268270
"""
269271
if mode == "all":
270272
for ax in self.axes_all:
@@ -292,6 +294,16 @@ def set_label_mode(self, mode):
292294

293295
ax = self.axes_llc
294296
_tick_only(ax, bottom_on=False, left_on=False)
297+
else:
298+
# Use _api.check_in_list at the top of the method when deprecation
299+
# period expires
300+
if mode != 'keep':
301+
_api.warn_deprecated(
302+
'3.7', name="Grid label_mode",
303+
message='Passing an undefined label_mode is deprecated '
304+
'since %(since)s and will become an error '
305+
'%(removal)s. To silence this warning, pass '
306+
'"keep", which gives the same behaviour.')
295307

296308
def get_divider(self):
297309
return self._divider

lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import matplotlib as mpl
55
import matplotlib.pyplot as plt
66
import matplotlib.ticker as mticker
7-
from matplotlib import cbook
7+
from matplotlib import _api, cbook
88
from matplotlib.backend_bases import MouseEvent
99
from matplotlib.colors import LogNorm
1010
from matplotlib.transforms import Bbox, TransformedBbox
@@ -411,6 +411,15 @@ def test_image_grid_single_bottom():
411411
grid.cbar_axes[0].colorbar(im)
412412

413413

414+
def test_image_grid_label_mode_deprecation_warning():
415+
imdata = np.arange(9).reshape((3, 3))
416+
417+
fig = plt.figure()
418+
with pytest.warns(_api.MatplotlibDeprecationWarning,
419+
match="Passing an undefined label_mode"):
420+
grid = ImageGrid(fig, (0, 0, 1, 1), (2, 1), label_mode="foo")
421+
422+
414423
@image_comparison(['image_grid.png'],
415424
remove_text=True, style='mpl20',
416425
savefig_kwarg={'bbox_inches': 'tight'})

0 commit comments

Comments
 (0)