Skip to content

Commit 30fddc3

Browse files
committed
fix Axes.hist to set labels correctly
1 parent 074425f commit 30fddc3

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/matplotlib/axes.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7811,22 +7811,26 @@ def hist(x, bins=10, range=None, normed=False, weights=None,
78117811
self.dataLim.intervaly = (ymin, ymax)
78127812

78137813
if label is None:
7814-
labels = ['_nolegend_']
7814+
labels = [None]
78157815
elif is_string_like(label):
78167816
labels = [label]
78177817
elif is_sequence_of_strings(label):
78187818
labels = list(label)
78197819
else:
7820-
raise ValueError(
7821-
'invalid label: must be string or sequence of strings')
7820+
raise ValueError('invalid label: must be string or sequence of strings')
7821+
78227822
if len(labels) < nx:
7823-
labels += ['_nolegend_'] * (nx - len(labels))
7823+
labels += [None] * (nx - len(labels))
78247824

78257825
for (patch, lbl) in zip(patches, labels):
7826-
for p in patch:
7826+
if patch:
7827+
p = patch[0]
78277828
p.update(kwargs)
7828-
p.set_label(lbl)
7829-
lbl = '_nolegend_'
7829+
if lbl is not None: p.set_label(lbl)
7830+
7831+
for p in patch[1:]:
7832+
p.update(kwargs)
7833+
p.set_label('_nolegend_')
78307834

78317835
if binsgiven:
78327836
if orientation == 'vertical':

0 commit comments

Comments
 (0)