3232import matplotlib .transforms as mtransforms
3333import matplotlib .tri as mtri
3434import matplotlib .units as munits
35- from matplotlib import _api , _docstring , _preprocess_data
35+ from matplotlib import _api , _docstring , _preprocess_data , _style_helpers
3636from matplotlib .axes ._base import (
3737 _AxesBase , _TransformedBoundsLocator , _process_plot_format )
3838from matplotlib .axes ._secondary_axes import SecondaryAxis
@@ -3194,6 +3194,16 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
31943194
31953195 **kwargs : `.Rectangle` properties
31963196
3197+ Properties applied to all bars. The following properties additionally
3198+ accept a sequence of values corresponding to the datasets in
3199+ *heights*:
3200+
3201+ - *edgecolor*
3202+ - *facecolor*
3203+ - *linewidth*
3204+ - *linestyle*
3205+ - *hatch*
3206+
31973207 %(Rectangle:kwdoc)s
31983208
31993209 Returns
@@ -3320,6 +3330,8 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
33203330 # TODO: do we want to be more restrictive and check lengths?
33213331 colors = itertools .cycle (colors )
33223332
3333+ kwargs , style_gen = _style_helpers .style_generator (kwargs )
3334+
33233335 bar_width = (group_distance /
33243336 (num_datasets + (num_datasets - 1 ) * bar_spacing + group_spacing ))
33253337 bar_spacing_abs = bar_spacing * bar_width
@@ -3333,15 +3345,16 @@ def grouped_bar(self, heights, *, positions=None, group_spacing=1.5, bar_spacing
33333345 # place the bars, but only use numerical positions, categorical tick labels
33343346 # are handled separately below
33353347 bar_containers = []
3336- for i , (hs , label , color ) in enumerate (zip (heights , labels , colors )):
3348+ for i , (hs , label , color , styles ) in enumerate (zip (heights , labels , colors ,
3349+ style_gen )):
33373350 lefts = (group_centers - 0.5 * group_distance + margin_abs
33383351 + i * (bar_width + bar_spacing_abs ))
33393352 if orientation == "vertical" :
33403353 bc = self .bar (lefts , hs , width = bar_width , align = "edge" ,
3341- label = label , color = color , ** kwargs )
3354+ label = label , color = color , ** styles , ** kwargs )
33423355 else :
33433356 bc = self .barh (lefts , hs , height = bar_width , align = "edge" ,
3344- label = label , color = color , ** kwargs )
3357+ label = label , color = color , ** styles , ** kwargs )
33453358 bar_containers .append (bc )
33463359
33473360 if tick_labels is not None :
@@ -7632,38 +7645,15 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
76327645 labels = [] if label is None else np .atleast_1d (np .asarray (label , str ))
76337646
76347647 if histtype == "step" :
7635- ec = kwargs .get ('edgecolor' , colors )
7636- else :
7637- ec = kwargs .get ('edgecolor' , None )
7638- if ec is None or cbook ._str_lower_equal (ec , 'none' ):
7639- edgecolors = itertools .repeat (ec )
7640- else :
7641- edgecolors = itertools .cycle (mcolors .to_rgba_array (ec ))
7642-
7643- fc = kwargs .get ('facecolor' , colors )
7644- if cbook ._str_lower_equal (fc , 'none' ):
7645- facecolors = itertools .repeat (fc )
7646- else :
7647- facecolors = itertools .cycle (mcolors .to_rgba_array (fc ))
7648+ kwargs .setdefault ('edgecolor' , colors )
76487649
7649- hatches = itertools .cycle (np .atleast_1d (kwargs .get ('hatch' , None )))
7650- linewidths = itertools .cycle (np .atleast_1d (kwargs .get ('linewidth' , None )))
7651- if 'linestyle' in kwargs :
7652- linestyles = itertools .cycle (mlines ._get_dash_patterns (kwargs ['linestyle' ]))
7653- else :
7654- linestyles = itertools .repeat (None )
7650+ kwargs , style_gen = _style_helpers .style_generator (kwargs )
76557651
76567652 for patch , lbl in itertools .zip_longest (patches , labels ):
76577653 if not patch :
76587654 continue
76597655 p = patch [0 ]
7660- kwargs .update ({
7661- 'hatch' : next (hatches ),
7662- 'linewidth' : next (linewidths ),
7663- 'linestyle' : next (linestyles ),
7664- 'edgecolor' : next (edgecolors ),
7665- 'facecolor' : next (facecolors ),
7666- })
7656+ kwargs .update (next (style_gen ))
76677657 p ._internal_update (kwargs )
76687658 if lbl is not None :
76697659 p .set_label (lbl )
0 commit comments