@@ -2966,7 +2966,7 @@ def sign(x):
2966
2966
2967
2967
@_preprocess_data ()
2968
2968
@_docstring .interpd
2969
- def broken_barh (self , xranges , yrange , ** kwargs ):
2969
+ def broken_barh (self , xranges , yrange , align = "bottom" , ** kwargs ):
2970
2970
"""
2971
2971
Plot a horizontal sequence of rectangles.
2972
2972
@@ -2979,8 +2979,16 @@ def broken_barh(self, xranges, yrange, **kwargs):
2979
2979
The x-positions and extents of the rectangles. For each tuple
2980
2980
(*xmin*, *xwidth*) a rectangle is drawn from *xmin* to *xmin* +
2981
2981
*xwidth*.
2982
- yrange : (*ymin *, *yheight*)
2982
+ yrange : (*ypos *, *yheight*)
2983
2983
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
2984
2992
2985
2993
Returns
2986
2994
-------
@@ -3015,7 +3023,15 @@ def broken_barh(self, xranges, yrange, **kwargs):
3015
3023
3016
3024
vertices = []
3017
3025
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
+
3019
3035
for xr in xranges : # convert the absolute values, not the x and dx
3020
3036
try :
3021
3037
x0 , dx = xr
0 commit comments