@@ -2063,6 +2063,20 @@ 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
+ print (x0 , x , dx , convert )
2070
+ try :
2071
+ # attempt to add the width to x0; this works for
2072
+ # datetime+timedelta, for instance
2073
+ dx = convert (x0 + dx ) - x
2074
+ except (TypeError , AttributeError ):
2075
+ # but doesn't work for 'string' + float, so just
2076
+ # see if the converter works on the float.
2077
+ dx = convert (dx )
2078
+ return dx
2079
+
2066
2080
@_preprocess_data (replace_names = ["x" , "left" ,
2067
2081
"height" , "width" ,
2068
2082
"y" , "bottom" ,
@@ -2232,23 +2246,25 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2232
2246
else :
2233
2247
raise ValueError ('invalid orientation: %s' % orientation )
2234
2248
2249
+ x , height , width , y , linewidth = np .broadcast_arrays (
2250
+ # Make args iterable too.
2251
+ np .atleast_1d (x ), height , width , y , linewidth )
2252
+
2235
2253
# lets do some conversions now since some types cannot be
2236
2254
# subtracted uniformly
2237
2255
if self .xaxis is not None :
2256
+ x0 = x
2238
2257
x = self .convert_xunits (x )
2239
- width = self .convert_xunits ( width )
2258
+ width = self ._convert_dx ( x0 , x , width , self . convert_xunits )
2240
2259
if xerr is not None :
2241
- xerr = self .convert_xunits ( xerr )
2260
+ xerr = self ._convert_dx ( x0 , x , xerr , self . convert_xunits )
2242
2261
2243
2262
if self .yaxis is not None :
2263
+ y0 = y
2244
2264
y = self .convert_yunits (y )
2245
- height = self .convert_yunits ( height )
2265
+ height = self ._convert_dx ( y0 , y , height , self . convert_yunits )
2246
2266
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 )
2267
+ yerr = self ._convert_dx (y0 , y , yerr , self .convert_yunits )
2252
2268
2253
2269
# Now that units have been converted, set the tick locations.
2254
2270
if orientation == 'vertical' :
0 commit comments