@@ -2011,6 +2011,19 @@ def step(self, x, y, *args, where='pre', data=None, **kwargs):
2011
2011
kwargs ['drawstyle' ] = 'steps-' + where
2012
2012
return self .plot (x , y , * args , data = data , ** kwargs )
2013
2013
2014
+ @staticmethod
2015
+ def _convert_dx (x0 , x , dx , convert ):
2016
+ """ Small helper to do logic of width conversion flexibly """
2017
+ try :
2018
+ # attempt to add the width to x0; this works for
2019
+ # datetime+timedelta, for instance
2020
+ dx = convert (x0 + dx ) - x
2021
+ except (TypeError , AttributeError ):
2022
+ # but doesn't work for 'string' + float, so just
2023
+ # see if the converter works on the float.
2024
+ dx = convert (dx )
2025
+ return dx
2026
+
2014
2027
@_preprocess_data ()
2015
2028
@docstring .dedent_interpd
2016
2029
def bar (self , x , height , width = 0.8 , bottom = None , * , align = "center" ,
@@ -2172,23 +2185,25 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2172
2185
else :
2173
2186
raise ValueError ('invalid orientation: %s' % orientation )
2174
2187
2188
+ x , height , width , y , linewidth = np .broadcast_arrays (
2189
+ # Make args iterable too.
2190
+ np .atleast_1d (x ), height , width , y , linewidth )
2191
+
2175
2192
# lets do some conversions now since some types cannot be
2176
2193
# subtracted uniformly
2177
2194
if self .xaxis is not None :
2195
+ x0 = x
2178
2196
x = self .convert_xunits (x )
2179
- width = self .convert_xunits ( width )
2197
+ width = self ._convert_dx ( x0 , x , width , self . convert_xunits )
2180
2198
if xerr is not None :
2181
- xerr = self .convert_xunits ( xerr )
2199
+ xerr = self ._convert_dx ( x0 , x , xerr , self . convert_xunits )
2182
2200
2183
2201
if self .yaxis is not None :
2202
+ y0 = y
2184
2203
y = self .convert_yunits (y )
2185
- height = self .convert_yunits ( height )
2204
+ height = self ._convert_dx ( y0 , y , height , self . convert_yunits )
2186
2205
if yerr is not None :
2187
- yerr = self .convert_yunits (yerr )
2188
-
2189
- x , height , width , y , linewidth = np .broadcast_arrays (
2190
- # Make args iterable too.
2191
- np .atleast_1d (x ), height , width , y , linewidth )
2206
+ yerr = self ._convert_dx (y0 , y , yerr , self .convert_yunits )
2192
2207
2193
2208
# Now that units have been converted, set the tick locations.
2194
2209
if orientation == 'vertical' :
@@ -2465,10 +2480,16 @@ def broken_barh(self, xranges, yrange, **kwargs):
2465
2480
self ._process_unit_info (xdata = xdata ,
2466
2481
ydata = ydata ,
2467
2482
kwargs = kwargs )
2468
- xranges = self .convert_xunits (xranges )
2483
+ xnew = []
2484
+ for xr in xranges :
2485
+ # convert the absolute values, not the x and dx...
2486
+ x0 = self .convert_xunits (xr [0 ])
2487
+ x1 = self ._convert_dx (xr [0 ], x0 , xr [1 ], self .convert_xunits )
2488
+ xnew .append ((x0 , x1 ))
2489
+
2469
2490
yrange = self .convert_yunits (yrange )
2470
2491
2471
- col = mcoll .BrokenBarHCollection (xranges , yrange , ** kwargs )
2492
+ col = mcoll .BrokenBarHCollection (xnew , yrange , ** kwargs )
2472
2493
self .add_collection (col , autolim = True )
2473
2494
self .autoscale_view ()
2474
2495
0 commit comments