Skip to content

Commit d7ffeaa

Browse files
committed
Added None patch test
1 parent 347ce22 commit d7ffeaa

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7226,20 +7226,21 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
72267226
linestyles = itertools.cycle(np.atleast_1d(kwargs.get('linestyle', None)))
72277227

72287228
for patch, lbl in itertools.zip_longest(patches, labels):
7229-
p = patch[0]
7230-
kwargs.update({
7231-
'hatch': next(hatches),
7232-
'linewidth': next(linewidths),
7233-
'linestyle': next(linestyles),
7234-
'edgecolor': next(edgecolors),
7235-
'facecolor': next(facecolors),
7236-
})
7237-
p._internal_update(kwargs)
7238-
if lbl is not None:
7239-
p.set_label(lbl)
7240-
for p in patch[1:]:
7229+
if patch:
7230+
p = patch[0]
7231+
kwargs.update({
7232+
'hatch': next(hatches),
7233+
'linewidth': next(linewidths),
7234+
'linestyle': next(linestyles),
7235+
'edgecolor': next(edgecolors),
7236+
'facecolor': next(facecolors),
7237+
})
72417238
p._internal_update(kwargs)
7242-
p.set_label('_nolegend_')
7239+
if lbl is not None:
7240+
p.set_label(lbl)
7241+
for p in patch[1:]:
7242+
p._internal_update(kwargs)
7243+
p.set_label('_nolegend_')
72437244

72447245
if nx == 1:
72457246
return tops[0], bins, patches[0]

lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4672,6 +4672,11 @@ def test_hist_emptydata():
46724672
ax.hist([[], range(10), range(10)], histtype="step")
46734673

46744674

4675+
def test_hist_none_patch():
4676+
x = [[1, 2], [2, 3]]
4677+
plt.hist(x, label=["First", "Second", "Third"])
4678+
4679+
46754680
def test_hist_labels():
46764681
# test singleton labels OK
46774682
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)