@@ -2498,8 +2498,8 @@ def barh(self, y, width, height=0.8, left=None, *, align="center",
24982498 align = align , ** kwargs )
24992499 return patches
25002500
2501- def bar_label (self , container , labels = None , * , fmt = "%g" , position = "edge" ,
2502- padding = 0 , shifting = 0 , ** kwargs ):
2501+ def bar_label (self , container , labels = None , * , fmt = "%g" , label_type = "edge" ,
2502+ padding = 0 , ** kwargs ):
25032503 """
25042504 Label a bar plot.
25052505
@@ -2518,18 +2518,18 @@ def bar_label(self, container, labels=None, *, fmt="%g", position="edge",
25182518 fmt : str, default: '%g'
25192519 A format string for the label.
25202520
2521- position : {'edge', 'center'}, default: 'edge'
2522- Position of the label relative to the bar :
2521+ label_type : {'edge', 'center'}, default: 'edge'
2522+ The label type, Possible values :
25232523
2524- - 'edge': the value is the position of the edge.
2525- (cumulative for stacked bars)
2526- - 'center': the value shown will be the length of the bar.
2524+ - 'edge': label placed at the end-point of the bar segment, and the
2525+ value displayed will be the position of that end-point.
2526+ - 'center': label placed in the center of the bar segment, and the
2527+ value displayed will be the length of that segment.
2528+ (useful for stacked bars, i.e.
2529+ :doc:`/gallery/lines_bars_and_markers/bar_label_demo`)
25272530
25282531 padding : float, default: 0
2529- Offset in points parallel to the direction of the bar.
2530-
2531- shifting : float, default: 0
2532- Offset in points perpendicular to the direction of the bar.
2532+ Distance of label from the end of the bar.
25332533
25342534 **kwargs : passed through to `.Axes.annotate`.
25352535
@@ -2544,7 +2544,7 @@ def bar_label(self, container, labels=None, *, fmt="%g", position="edge",
25442544 def sign (x ):
25452545 return 1 if x >= 0 else - 1
25462546
2547- cbook ._check_in_list (['edge' , 'center' ], position = position )
2547+ cbook ._check_in_list (['edge' , 'center' ], label_type = label_type )
25482548
25492549 bars = container .patches
25502550 errorbar = container .errorbar
@@ -2579,35 +2579,34 @@ def sign(x):
25792579 elif orientation == "horizontal" :
25802580 endpt = err [:, 0 ].max () if xc >= 0 else err [:, 0 ].min ()
25812581
2582- if position == "center" :
2582+ if label_type == "center" :
25832583 value = sign (extrema ) * length
2584- elif position == "edge" :
2584+ elif label_type == "edge" :
25852585 value = extrema
25862586
2587- if position == "center" :
2587+ if label_type == "center" :
25882588 xy = xc , yc
2589- elif position == "edge" and orientation == "vertical" :
2589+ elif label_type == "edge" and orientation == "vertical" :
25902590 xy = xc , endpt
2591- elif position == "edge" and orientation == "horizontal" :
2591+ elif label_type == "edge" and orientation == "horizontal" :
25922592 xy = endpt , yc
25932593
25942594 if orientation == "vertical" :
2595- xytext = shifting , sign (extrema ) * padding
2595+ xytext = 0 , sign (extrema ) * padding
25962596 else :
2597- xytext = sign (extrema ) * padding , shifting
2597+ xytext = sign (extrema ) * padding , 0
25982598
2599- if position == "center" :
2599+ if label_type == "center" :
26002600 ha , va = "center" , "center"
2601- elif position == "edge" and orientation == "vertical" and yc >= 0 :
2602- ha , va = "center" , "bottom"
2603- elif position == "edge" and orientation == "vertical" and yc < 0 :
2604- ha , va = "center" , "top"
2605- elif (
2606- position == "edge" and orientation == "horizontal" and xc >= 0
2607- ):
2608- ha , va = "left" , "center"
2609- elif position == "edge" and orientation == "horizontal" and xc < 0 :
2610- ha , va = "right" , "center"
2601+ elif label_type == "edge" :
2602+ if orientation == "vertical" and yc >= 0 :
2603+ ha , va = "center" , "bottom"
2604+ elif orientation == "vertical" and yc < 0 :
2605+ ha , va = "center" , "top"
2606+ elif orientation == "horizontal" and xc >= 0 :
2607+ ha , va = "left" , "center"
2608+ elif orientation == "horizontal" and xc < 0 :
2609+ ha , va = "right" , "center"
26112610
26122611 annotation = self .annotate (fmt % value if lbl is None else lbl ,
26132612 xy , xytext , textcoords = "offset points" ,
0 commit comments