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

Skip to content

Commit 2d610df

Browse files
committed
FIX: single label per boxplot
1 parent 630ebba commit 2d610df

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4004,9 +4004,6 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
40044004
if 'color' in boxprops:
40054005
boxprops['edgecolor'] = boxprops.pop('color')
40064006

4007-
if labels:
4008-
boxprops['label'] = labels
4009-
40104007
# if non-default sym value, put it into the flier dictionary
40114008
# the logic for providing the default symbol ('b+') now lives
40124009
# in bxp in the initial value of flierkw
@@ -4279,7 +4276,12 @@ def do_patch(xs, ys, **kwargs):
42794276
for pos, width, stats, capwidth in zip(positions, widths, bxpstats,
42804277
capwidths):
42814278
# try to find a new label
4282-
datalabels.append(stats.get('label', pos))
4279+
if (label := stats.get('label')) is None:
4280+
datalabels.append(pos)
4281+
box_kw.pop('label', None)
4282+
else:
4283+
datalabels.append(label)
4284+
box_kw['label'] = label
42834285

42844286
# whisker coords
42854287
whis_x = [pos, pos]

lib/matplotlib/tests/test_legend.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,3 +1467,13 @@ def test_boxplot_legend():
14671467
assert handle.get_facecolor() == colors[index]
14681468
assert handle.get_edgecolor() == colors[index]
14691469
assert handle.get_label() == labels[index]
1470+
1471+
1472+
def test_boxplot_multi_label():
1473+
# Smoke test that we can pass a 2D array and sequence of labels.
1474+
fig, ax = plt.subplots()
1475+
1476+
A = np.arange(30).reshape(10, 3)
1477+
labels = ['a', 'b', 'c']
1478+
1479+
ax.boxplot(A, labels=labels)

0 commit comments

Comments
 (0)