@@ -2321,6 +2321,56 @@ def _convert_dx(dx, x0, xconv, convert):
2321
2321
dx = convert (dx )
2322
2322
return dx
2323
2323
2324
+ def _parse_bar_color_args (self , kwargs ):
2325
+ """
2326
+ Helper function to process color-related arguments of `.Axes.bar`.
2327
+
2328
+ Argument precedence for facecolors:
2329
+
2330
+ - kwargs['facecolor']
2331
+ - kwargs['color']
2332
+ - 'Result of ``self._get_patches_for_fill.get_next_color``
2333
+
2334
+ Argument precedence for edgecolors:
2335
+
2336
+ - kwargs['edgecolor']
2337
+ - None
2338
+
2339
+ Parameters
2340
+ ----------
2341
+ self : Axes
2342
+
2343
+ kwargs : dict
2344
+ Additional kwargs. If these keys exist, we pop and process them:
2345
+ 'facecolor', 'edgecolor', 'color'
2346
+ Note: The dict is modified by this function.
2347
+
2348
+
2349
+ Returns
2350
+ -------
2351
+ facecolor
2352
+ The facecolor. One or more colors as (N, 4) rgba array.
2353
+ edgecolor
2354
+ The edgecolor. Not normalized; may be any valid color spec or None.
2355
+ """
2356
+ color = kwargs .pop ('color' , None )
2357
+
2358
+ facecolor = kwargs .pop ('facecolor' , color )
2359
+ edgecolor = kwargs .pop ('edgecolor' , None )
2360
+
2361
+ facecolor = (facecolor if facecolor is not None
2362
+ else self ._get_patches_for_fill .get_next_color ())
2363
+
2364
+ try :
2365
+ facecolor = mcolors .to_rgba_array (facecolor )
2366
+ except ValueError as err :
2367
+ raise ValueError (
2368
+ "'facecolor' or 'color' argument must be a valid color or"
2369
+ "sequence of colors."
2370
+ ) from err
2371
+
2372
+ return facecolor , edgecolor
2373
+
2324
2374
@_preprocess_data ()
2325
2375
@_docstring .interpd
2326
2376
def bar (self , x , height , width = 0.8 , bottom = None , * , align = "center" ,
@@ -2376,7 +2426,12 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2376
2426
Other Parameters
2377
2427
----------------
2378
2428
color : :mpltype:`color` or list of :mpltype:`color`, optional
2429
+ The colors of the bar faces. This is an alias for *facecolor*.
2430
+ If both are given, *facecolor* takes precedence.
2431
+
2432
+ facecolor : :mpltype:`color` or list of :mpltype:`color`, optional
2379
2433
The colors of the bar faces.
2434
+ If both *color* and *facecolor are given, *facecolor* takes precedence.
2380
2435
2381
2436
edgecolor : :mpltype:`color` or list of :mpltype:`color`, optional
2382
2437
The colors of the bar edges.
@@ -2441,10 +2496,8 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2441
2496
bar. See :doc:`/gallery/lines_bars_and_markers/bar_stacked`.
2442
2497
"""
2443
2498
kwargs = cbook .normalize_kwargs (kwargs , mpatches .Patch )
2444
- color = kwargs .pop ('color' , None )
2445
- if color is None :
2446
- color = self ._get_patches_for_fill .get_next_color ()
2447
- edgecolor = kwargs .pop ('edgecolor' , None )
2499
+ facecolor , edgecolor = self ._parse_bar_color_args (kwargs )
2500
+
2448
2501
linewidth = kwargs .pop ('linewidth' , None )
2449
2502
hatch = kwargs .pop ('hatch' , None )
2450
2503
@@ -2540,9 +2593,9 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2540
2593
2541
2594
linewidth = itertools .cycle (np .atleast_1d (linewidth ))
2542
2595
hatch = itertools .cycle (np .atleast_1d (hatch ))
2543
- color = itertools .chain (itertools .cycle (mcolors . to_rgba_array ( color ) ),
2544
- # Fallback if color == "none".
2545
- itertools .repeat ('none' ))
2596
+ facecolor = itertools .chain (itertools .cycle (facecolor ),
2597
+ # Fallback if color == "none".
2598
+ itertools .repeat ('none' ))
2546
2599
if edgecolor is None :
2547
2600
edgecolor = itertools .repeat (None )
2548
2601
else :
@@ -2576,7 +2629,7 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2576
2629
bottom = y
2577
2630
2578
2631
patches = []
2579
- args = zip (left , bottom , width , height , color , edgecolor , linewidth ,
2632
+ args = zip (left , bottom , width , height , facecolor , edgecolor , linewidth ,
2580
2633
hatch , patch_labels )
2581
2634
for l , b , w , h , c , e , lw , htch , lbl in args :
2582
2635
r = mpatches .Rectangle (
0 commit comments