@@ -6335,10 +6335,10 @@ def table(self, **kwargs):
6335
6335
@_preprocess_data (replace_names = ["x" , 'weights' ], label_namer = "x" )
6336
6336
def hist (self , x , bins = None , range = None , density = None , weights = None ,
6337
6337
cumulative = False , bottom = None , histtype = 'bar' , align = 'mid' ,
6338
- orientation = 'vertical' , rwidth = None , log = False ,
6339
- color = None , label = None , stacked = False , normed = None ,
6338
+ orientation = 'vertical' , rwidth = None , log = False , color = None ,
6339
+ label = None , stacked = False , normed = None ,
6340
6340
** kwargs ):
6341
- """
6341
+ r """
6342
6342
Plot a histogram.
6343
6343
6344
6344
Compute and draw the histogram of *x*. The return value is a
@@ -6440,7 +6440,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6440
6440
6441
6441
Default is ``None``
6442
6442
6443
- histtype : {'bar', 'barstacked', 'step', 'stepfilled'}, optional
6443
+ histtype : {'bar', 'barstacked', 'step', 'stepfilled'}, optional
6444
6444
The type of histogram to draw.
6445
6445
6446
6446
- 'bar' is a traditional bar-type histogram. If multiple data
@@ -6488,12 +6488,6 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6488
6488
6489
6489
Default is ``False``
6490
6490
6491
- color : color or array_like of colors or None, optional
6492
- Color spec or sequence of color specs, one per dataset. Default
6493
- (``None``) uses the standard line color sequence.
6494
-
6495
- Default is ``None``
6496
-
6497
6491
label : str or None, optional
6498
6492
String, or sequence of strings to match multiple datasets. Bar
6499
6493
charts yield multiple patches per dataset, but only the first gets
@@ -6535,6 +6529,39 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6535
6529
6536
6530
Other Parameters
6537
6531
----------------
6532
+ color : color or array_like of colors or None, optional
6533
+ The meaning of the parameter depends on *histtype*:
6534
+
6535
+ - For filled *histtype*\s ('bar', 'barstacked' and 'stepfilled'):
6536
+
6537
+ The facecolor of the bars. If providing multiple datasets to
6538
+ *x*, there must be one color per dataset. If *None* the
6539
+ standard line color sequence is used.
6540
+
6541
+ The *color* parameter is overridden if *facecolor* is given.
6542
+
6543
+ - For *histtype* 'step':
6544
+
6545
+ The linecolor of the step line. If None the standard line color
6546
+ sequence is used.
6547
+
6548
+ Default: *None*
6549
+
6550
+ edgecolor : color or array_like of colors, optional
6551
+ The edgecolor of the bars. If providing multiple datasets to
6552
+ *x*, you can either pass a single edgecolor for all datasets or
6553
+ one edgecolor per dataset. If not given, use :rc:`hist.edgecolor`.
6554
+ If that is *None*, the default patch settings are used
6555
+ (:rc:`patch.edgecolor` and :rc:`patch.force_edgecolor`).
6556
+
6557
+ Note: *edgecolor* is ignored for *histtype* 'step'. Use *color*
6558
+ in this case.
6559
+
6560
+ linewidth : float, optional
6561
+ The linewidth of the bar edges. If not given, use
6562
+ :rc:`hist.linewidth`. If that is *None*, the default
6563
+ :rc:`patch.linewidth` is used.
6564
+
6538
6565
**kwargs : `~matplotlib.patches.Patch` properties
6539
6566
6540
6567
See also
@@ -6546,6 +6573,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6546
6573
.. [Notes section required for data comment. See #10189.]
6547
6574
6548
6575
"""
6576
+ kwargs = cbook .normalize_kwargs (kwargs , mpatches .Patch ._alias_map )
6577
+
6549
6578
# Avoid shadowing the builtin.
6550
6579
bin_range = range
6551
6580
from builtins import range
@@ -6619,10 +6648,25 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6619
6648
else :
6620
6649
color = mcolors .to_rgba_array (color )
6621
6650
if len (color ) != nx :
6622
- error_message = (
6651
+ raise ValueError (
6623
6652
"color kwarg must have one color per data set. %d data "
6624
6653
"sets and %d colors were provided" % (nx , len (color )))
6625
- raise ValueError (error_message )
6654
+
6655
+ edgecolor = kwargs .pop ('edgecolor' , rcParams ['hist.edgecolor' ])
6656
+ if edgecolor is None :
6657
+ edgecolor = [None ] * nx
6658
+ else :
6659
+ edgecolor = mcolors .to_rgba_array (edgecolor )
6660
+ if len (edgecolor ) == 1 :
6661
+ edgecolor = np .repeat (nx , axis = 0 )
6662
+ elif len (edgecolor ) != nx :
6663
+ raise ValueError (
6664
+ "edgecolor kwarg must have one color per data set. "
6665
+ "%d data sets and %d colors were provided" % (
6666
+ nx , len (edgecolor )))
6667
+
6668
+ if rcParams ['hist.linewidth' ] is not None :
6669
+ kwargs .setdefault ('linewidth' , rcParams ['hist.linewidth' ])
6626
6670
6627
6671
# If bins are not specified either explicitly or via range,
6628
6672
# we need to figure out the range required for all datasets,
@@ -6715,7 +6759,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6715
6759
_barfunc = self .bar
6716
6760
bottom_kwarg = 'bottom'
6717
6761
6718
- for m , c in zip (tops , color ):
6762
+ for m , c , ec in zip (tops , color , edgecolor ):
6719
6763
if bottom is None :
6720
6764
bottom = np .zeros (len (m ))
6721
6765
if stacked :
@@ -6724,7 +6768,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6724
6768
height = m
6725
6769
patch = _barfunc (bins [:- 1 ]+ boffset , height , width ,
6726
6770
align = 'center' , log = log ,
6727
- color = c , ** {bottom_kwarg : bottom })
6771
+ color = c , edgecolor = ec ,
6772
+ ** {bottom_kwarg : bottom })
6728
6773
patches .append (patch )
6729
6774
if stacked :
6730
6775
bottom [:] = m
@@ -6805,12 +6850,13 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
6805
6850
# add patches in reverse order so that when stacking,
6806
6851
# items lower in the stack are plotted on top of
6807
6852
# items higher in the stack
6808
- for x , y , c in reversed (list (zip (xvals , yvals , color ))):
6853
+ for x , y , c , ec in reversed (list (zip (xvals , yvals , color ,
6854
+ edgecolor ))):
6809
6855
patches .append (self .fill (
6810
6856
x [:split ], y [:split ],
6811
6857
closed = True if fill else None ,
6812
6858
facecolor = c ,
6813
- edgecolor = None if fill else c ,
6859
+ edgecolor = ec if fill else c ,
6814
6860
fill = fill if fill else None ))
6815
6861
for patch_list in patches :
6816
6862
for patch in patch_list :
0 commit comments