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

Skip to content

Commit be1ebc2

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

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 3 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
@@ -4280,6 +4277,7 @@ def do_patch(xs, ys, **kwargs):
42804277
capwidths):
42814278
# try to find a new label
42824279
datalabels.append(stats.get('label', pos))
4280+
box_kw['label'] = stats.get('label', None)
42834281

42844282
# whisker coords
42854283
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)