@@ -2063,6 +2063,19 @@ def step(self, x, y, *args, where='pre', **kwargs):
2063
2063
kwargs ['drawstyle' ] = 'steps-' + where
2064
2064
return self .plot (x , y , * args , ** kwargs )
2065
2065
2066
+ @staticmethod
2067
+ def _convert_dx (x0 , x , dx , convert ):
2068
+ """ Small helper to do logic of width conversion flexibly """
2069
+ try :
2070
+ # attempt to add the width to x0; this works for
2071
+ # datetime+timedelta, for instance
2072
+ dx = convert (x0 + dx ) - x
2073
+ except (TypeError , AttributeError ):
2074
+ # but doesn't work for 'string' + float, so just
2075
+ # see if the converter works on the float.
2076
+ dx = convert (dx )
2077
+ return dx
2078
+
2066
2079
@_preprocess_data (replace_names = ["x" , "left" ,
2067
2080
"height" , "width" ,
2068
2081
"y" , "bottom" ,
@@ -2232,23 +2245,25 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2232
2245
else :
2233
2246
raise ValueError ('invalid orientation: %s' % orientation )
2234
2247
2248
+ x , height , width , y , linewidth = np .broadcast_arrays (
2249
+ # Make args iterable too.
2250
+ np .atleast_1d (x ), height , width , y , linewidth )
2251
+
2235
2252
# lets do some conversions now since some types cannot be
2236
2253
# subtracted uniformly
2237
2254
if self .xaxis is not None :
2255
+ x0 = x
2238
2256
x = self .convert_xunits (x )
2239
- width = self .convert_xunits ( width )
2257
+ width = self ._convert_dx ( x0 , x , width , self . convert_xunits )
2240
2258
if xerr is not None :
2241
- xerr = self .convert_xunits ( xerr )
2259
+ xerr = self ._convert_dx ( x0 , x , xerr , self . convert_xunits )
2242
2260
2243
2261
if self .yaxis is not None :
2262
+ y0 = y
2244
2263
y = self .convert_yunits (y )
2245
- height = self .convert_yunits ( height )
2264
+ height = self ._convert_dx ( y0 , y , height , self . convert_yunits )
2246
2265
if yerr is not None :
2247
- yerr = self .convert_yunits (yerr )
2248
-
2249
- x , height , width , y , linewidth = np .broadcast_arrays (
2250
- # Make args iterable too.
2251
- np .atleast_1d (x ), height , width , y , linewidth )
2266
+ yerr = self ._convert_dx (y0 , y , yerr , self .convert_yunits )
2252
2267
2253
2268
# Now that units have been converted, set the tick locations.
2254
2269
if orientation == 'vertical' :
@@ -2528,11 +2543,9 @@ def broken_barh(self, xranges, yrange, **kwargs):
2528
2543
xnew = []
2529
2544
for xr in xranges :
2530
2545
# convert the absolute values, not the x and dx...
2531
- x0 = [self .convert_xunits (xr [0 ]),
2532
- self .convert_xunits (xr [0 ]+ xr [1 ])]
2533
- # make a dx again...
2534
- x0 [1 ] = x0 [1 ] - x0 [0 ]
2535
- xnew .append (x0 )
2546
+ x0 = self .convert_xunits (xr [0 ])
2547
+ x1 = self ._convert_dx (xr [0 ], x0 , xr [1 ], self .convert_xunits )
2548
+ xnew .append ((x0 , x1 ))
2536
2549
2537
2550
yrange = self .convert_yunits (yrange )
2538
2551
0 commit comments