@@ -2826,10 +2826,6 @@ def broken_barh(self, xranges, yrange, **kwargs):
28262826 A rectangle is drawn for each element of *xranges*. All rectangles
28272827 have the same vertical position and size defined by *yrange*.
28282828
2829- This is a convenience function for instantiating a
2830- `.BrokenBarHCollection`, adding it to the Axes and autoscaling the
2831- view.
2832-
28332829 Parameters
28342830 ----------
28352831 xranges : sequence of tuples (*xmin*, *xwidth*)
@@ -2841,13 +2837,13 @@ def broken_barh(self, xranges, yrange, **kwargs):
28412837
28422838 Returns
28432839 -------
2844- `~.collections.BrokenBarHCollection `
2840+ `~.collections.PolyCollection `
28452841
28462842 Other Parameters
28472843 ----------------
28482844 data : indexable object, optional
28492845 DATA_PARAMETER_PLACEHOLDER
2850- **kwargs : `.BrokenBarHCollection ` properties
2846+ **kwargs : `.PolyCollection ` properties
28512847
28522848 Each *kwarg* can be either a single argument applying to all
28532849 rectangles, e.g.::
@@ -2862,32 +2858,28 @@ def broken_barh(self, xranges, yrange, **kwargs):
28622858
28632859 Supported keywords:
28642860
2865- %(BrokenBarHCollection :kwdoc)s
2861+ %(PolyCollection :kwdoc)s
28662862 """
28672863 # process the unit information
2868- if len (xranges ):
2869- xdata = cbook ._safe_first_finite (xranges )
2870- else :
2871- xdata = None
2872- if len (yrange ):
2873- ydata = cbook ._safe_first_finite (yrange )
2874- else :
2875- ydata = None
2864+ xdata = cbook ._safe_first_finite (xranges ) if len (xranges ) else None
2865+ ydata = cbook ._safe_first_finite (yrange ) if len (yrange ) else None
28762866 self ._process_unit_info (
28772867 [("x" , xdata ), ("y" , ydata )], kwargs , convert = False )
2878- xranges_conv = []
2879- for xr in xranges :
2880- if len (xr ) != 2 :
2881- raise ValueError ('each range in xrange must be a sequence '
2882- 'with two elements (i.e. an Nx2 array)' )
2883- # convert the absolute values, not the x and dx...
2884- x_conv = np .asarray (self .convert_xunits (xr [0 ]))
2885- x1 = self ._convert_dx (xr [1 ], xr [0 ], x_conv , self .convert_xunits )
2886- xranges_conv .append ((x_conv , x1 ))
2887-
2888- yrange_conv = self .convert_yunits (yrange )
2889-
2890- col = mcoll .BrokenBarHCollection (xranges_conv , yrange_conv , ** kwargs )
2868+
2869+ vertices = []
2870+ y0 , dy = yrange
2871+ y0 , y1 = self .convert_yunits ((y0 , y0 + dy ))
2872+ for xr in xranges : # convert the absolute values, not the x and dx
2873+ try :
2874+ x0 , dx = xr
2875+ except Exception :
2876+ raise ValueError (
2877+ "each range in xrange must be a sequence with two "
2878+ "elements (i.e. xrange must be an (N, 2) array)" ) from None
2879+ x0 , x1 = self .convert_xunits ((x0 , x0 + dx ))
2880+ vertices .append ([(x0 , y0 ), (x0 , y1 ), (x1 , y1 ), (x1 , y0 )])
2881+
2882+ col = mcoll .PolyCollection (np .array (vertices ), ** kwargs )
28912883 self .add_collection (col , autolim = True )
28922884 self ._request_autoscale_view ()
28932885
0 commit comments