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

Skip to content

Commit 49cbec6

Browse files
committed
Add support for multiple hatches, edgecolor and linewidth in histograms
1 parent 2834da1 commit 49cbec6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7210,9 +7210,34 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
72107210
# If None, make all labels None (via zip_longest below); otherwise,
72117211
# cast each element to str, but keep a single str as it.
72127212
labels = [] if label is None else np.atleast_1d(np.asarray(label, str))
7213+
7214+
if 'hatch' in kwargs:
7215+
if not isinstance(kwargs['hatch'], str):
7216+
hatches = itertools.cycle(kwargs['hatch'])
7217+
else:
7218+
hatches = itertools.cycle([kwargs['hatch']])
7219+
7220+
if 'edgecolor' in kwargs:
7221+
if not isinstance(kwargs['edgecolor'], str):
7222+
edgecolors = itertools.cycle(kwargs['edgecolor'])
7223+
else:
7224+
edgecolors = itertools.cycle([kwargs['edgecolor']])
7225+
7226+
if 'linewidth' in kwargs:
7227+
if isinstance(kwargs['linewidth'], list or tuple):
7228+
linewidths = itertools.cycle(kwargs['linewidth'])
7229+
else:
7230+
linewidths = itertools.cycle([kwargs['linewidth']])
7231+
72137232
for patch, lbl in itertools.zip_longest(patches, labels):
72147233
if patch:
72157234
p = patch[0]
7235+
if 'hatch' in kwargs:
7236+
kwargs['hatch'] = next(hatches)
7237+
if 'edgecolor' in kwargs:
7238+
kwargs['edgecolor'] = next(edgecolors)
7239+
if 'linewidth' in kwargs:
7240+
kwargs['linewidth'] = next(linewidths)
72167241
p._internal_update(kwargs)
72177242
if lbl is not None:
72187243
p.set_label(lbl)

0 commit comments

Comments
 (0)