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 7c2ea8f

Browse filesBrowse files
committed
rename tick label
1 parent f007886 commit 7c2ea8f
Copy full SHA for 7c2ea8f

File tree

Expand file treeCollapse file tree

7 files changed

+40
-27
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+40
-27
lines changed
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``boxplot`` tick labels
2+
~~~~~~~~~~~~~~~~~~~~~~~
3+
This has been renamed to *tick_labels* for clarity and consistency with`~.Axes.bar`.

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3789,12 +3789,13 @@ def apply_mask(arrays, mask):
37893789
return errorbar_container # (l0, caplines, barcols)
37903790

37913791
@_preprocess_data()
3792+
@_api.rename_parameter("3.9", "labels", "tick_labels")
37923793
def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
37933794
positions=None, widths=None, patch_artist=None,
37943795
bootstrap=None, usermedians=None, conf_intervals=None,
37953796
meanline=None, showmeans=None, showcaps=None,
37963797
showbox=None, showfliers=None, boxprops=None,
3797-
labels=None, flierprops=None, medianprops=None,
3798+
tick_labels=None, flierprops=None, medianprops=None,
37983799
meanprops=None, capprops=None, whiskerprops=None,
37993800
manage_ticks=True, autorange=False, zorder=None,
38003801
capwidths=None):
@@ -3908,9 +3909,11 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
39083909
If `False` produces boxes with the Line2D artist. Otherwise,
39093910
boxes are drawn with Patch artists.
39103911
3911-
labels : sequence, optional
3912-
Labels for each dataset (one per dataset). These are used for
3913-
x-tick labels; *not* for legend entries.
3912+
tick_labels : sequence, optional
3913+
The tick labels of each boxplot.
3914+
Default: None (Use default numeric labels.)
3915+
3916+
.. versionchanged:: 3.9
39143917
39153918
manage_ticks : bool, default: True
39163919
If True, the tick locations and labels will be adjusted to match
@@ -3994,7 +3997,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
39943997
bootstrap = mpl.rcParams['boxplot.bootstrap']
39953998

39963999
bxpstats = cbook.boxplot_stats(x, whis=whis, bootstrap=bootstrap,
3997-
labels=labels, autorange=autorange)
4000+
tick_labels=tick_labels, autorange=autorange)
39984001
if notch is None:
39994002
notch = mpl.rcParams['boxplot.notch']
40004003
if vert is None:

‎lib/matplotlib/axes/_axes.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.pyi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ class Axes(_AxesBase):
362362
showbox: bool | None = ...,
363363
showfliers: bool | None = ...,
364364
boxprops: dict[str, Any] | None = ...,
365-
labels: Sequence[str] | None = ...,
365+
tick_labels: Sequence[str] | None = ...,
366366
flierprops: dict[str, Any] | None = ...,
367367
medianprops: dict[str, Any] | None = ...,
368368
meanprops: dict[str, Any] | None = ...,

‎lib/matplotlib/cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.py
+10-7Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,8 @@ def _broadcast_with_masks(*args, compress=False):
11261126
return inputs
11271127

11281128

1129-
def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None,
1129+
@_api.rename_parameter("3.9", "labels", "tick_labels")
1130+
def boxplot_stats(X, whis=1.5, bootstrap=None, tick_labels=None,
11301131
autorange=False):
11311132
r"""
11321133
Return a list of dictionaries of statistics used to draw a series of box
@@ -1161,10 +1162,12 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None,
11611162
Number of times the confidence intervals around the median
11621163
should be bootstrapped (percentile method).
11631164
1164-
labels : array-like, optional
1165+
tick_labels : array-like, optional
11651166
Labels for each dataset. Length must be compatible with
11661167
dimensions of *X*.
11671168
1169+
.. versionchanged:: 3.9
1170+
11681171
autorange : bool, optional (False)
11691172
When `True` and the data are distributed such that the 25th and 75th
11701173
percentiles are equal, ``whis`` is set to (0, 100) such that the
@@ -1240,13 +1243,13 @@ def _compute_conf_interval(data, med, iqr, bootstrap):
12401243
X = _reshape_2D(X, "X")
12411244

12421245
ncols = len(X)
1243-
if labels is None:
1244-
labels = itertools.repeat(None)
1245-
elif len(labels) != ncols:
1246-
raise ValueError("Dimensions of labels and X must be compatible")
1246+
if tick_labels is None:
1247+
tick_labels = itertools.repeat(None)
1248+
elif len(tick_labels) != ncols:
1249+
raise ValueError("Dimensions of tick labels and X must be compatible")
12471250

12481251
input_whis = whis
1249-
for ii, (x, label) in enumerate(zip(X, labels)):
1252+
for ii, (x, label) in enumerate(zip(X, tick_labels)):
12501253

12511254
# empty dict
12521255
stats = {}

‎lib/matplotlib/cbook.pyi

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.pyi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def boxplot_stats(
135135
X: ArrayLike,
136136
whis: float | tuple[float, float] = ...,
137137
bootstrap: int | None = ...,
138-
labels: ArrayLike | None = ...,
138+
tick_labels: ArrayLike | None = ...,
139139
autorange: bool = ...,
140140
) -> list[dict[str, Any]]: ...
141141

‎lib/matplotlib/pyplot.py

Copy file name to clipboardExpand all lines: lib/matplotlib/pyplot.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2852,7 +2852,7 @@ def boxplot(
28522852
showbox: bool | None = None,
28532853
showfliers: bool | None = None,
28542854
boxprops: dict[str, Any] | None = None,
2855-
labels: Sequence[str] | None = None,
2855+
tick_labels: Sequence[str] | None = None,
28562856
flierprops: dict[str, Any] | None = None,
28572857
medianprops: dict[str, Any] | None = None,
28582858
meanprops: dict[str, Any] | None = None,
@@ -2883,7 +2883,7 @@ def boxplot(
28832883
showbox=showbox,
28842884
showfliers=showfliers,
28852885
boxprops=boxprops,
2886-
labels=labels,
2886+
tick_labels=tick_labels,
28872887
flierprops=flierprops,
28882888
medianprops=medianprops,
28892889
meanprops=meanprops,

‎lib/matplotlib/tests/test_legend.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_legend.py
+15-11Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,16 +1437,20 @@ def test_legend_text():
14371437
assert_allclose(leg_bboxes[1].bounds, leg_bboxes[0].bounds)
14381438

14391439

1440-
def test_boxplot_labels():
1441-
# Test that boxplot(..., labels=) sets the tick labels but not legend entries
1442-
# This is not consistent with other plot types but is the current behavior.
1443-
fig, ax = plt.subplots()
1440+
def test_boxplot_tick_labels():
1441+
# Test the renamed `tick_labels` parameter.
1442+
# Test for deprecation of old name `labels`.
1443+
np.random.seed(19680801)
14441444
np.random.seed(19680801)
14451445
data = np.random.random((10, 3))
1446-
bp = ax.boxplot(data, labels=['A', 'B', 'C'])
1447-
# Check that labels set the tick labels ...
1448-
assert [l.get_text() for l in ax.get_xticklabels()] == ['A', 'B', 'C']
1449-
# ... but not legend entries
1450-
handles, labels = ax.get_legend_handles_labels()
1451-
assert len(handles) == 0
1452-
assert len(labels) == 0
1446+
1447+
fig, axs = plt.subplots(nrows=1, ncols=2, sharey=True)
1448+
# Should get deprecation warning for `labels`
1449+
with pytest.warns(mpl.MatplotlibDeprecationWarning,
1450+
match='has been renamed \'tick_labels\''):
1451+
axs[0].boxplot(data, labels=['A', 'B', 'C'])
1452+
assert [l.get_text() for l in axs[0].get_xticklabels()] == ['A', 'B', 'C']
1453+
1454+
# Test the new tick_labels parameter
1455+
axs[1].boxplot(data, tick_labels=['A', 'B', 'C'])
1456+
assert [l.get_text() for l in axs[1].get_xticklabels()] == ['A', 'B', 'C']

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.