@@ -2966,7 +2966,7 @@ def sign(x):
29662966
29672967 @_preprocess_data ()
29682968 @_docstring .interpd
2969- def broken_barh (self , xranges , yrange , ** kwargs ):
2969+ def broken_barh (self , xranges , yrange , align = "bottom" , ** kwargs ):
29702970 """
29712971 Plot a horizontal sequence of rectangles.
29722972
@@ -2979,8 +2979,16 @@ def broken_barh(self, xranges, yrange, **kwargs):
29792979 The x-positions and extents of the rectangles. For each tuple
29802980 (*xmin*, *xwidth*) a rectangle is drawn from *xmin* to *xmin* +
29812981 *xwidth*.
2982- yrange : (*ymin *, *yheight*)
2982+ yrange : (*ypos *, *yheight*)
29832983 The y-position and extent for all the rectangles.
2984+ align : {"bottom", "center", "top"}, default: 'bottom'
2985+ The alignment of the yrange with respect to the y-position. One of:
2986+
2987+ - "bottom": Resulting y-range [ypos, ypos + yheight]
2988+ - "center": Resulting y-range [ypos - yheight/2, ypos + yheight/2]
2989+ - "top": Resulting y-range [ypos - yheight, ypos]
2990+
2991+ .. versionadded:: 3.11
29842992
29852993 Returns
29862994 -------
@@ -3015,7 +3023,15 @@ def broken_barh(self, xranges, yrange, **kwargs):
30153023
30163024 vertices = []
30173025 y0 , dy = yrange
3018- y0 , y1 = self .convert_yunits ((y0 , y0 + dy ))
3026+
3027+ _api .check_in_list (['bottom' , 'center' , 'top' ], align = align )
3028+ if align == "bottom" :
3029+ y0 , y1 = self .convert_yunits ((y0 , y0 + dy ))
3030+ elif align == "center" :
3031+ y0 , y1 = self .convert_yunits ((y0 - dy / 2 , y0 + dy / 2 ))
3032+ else :
3033+ y0 , y1 = self .convert_yunits ((y0 - dy , y0 ))
3034+
30193035 for xr in xranges : # convert the absolute values, not the x and dx
30203036 try :
30213037 x0 , dx = xr
0 commit comments