Skip to content

Commit 563c41a

Browse files
committed
FIX: make bar work with timedeltas
1 parent 3e8129b commit 563c41a

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,23 +2232,38 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
22322232
else:
22332233
raise ValueError('invalid orientation: %s' % orientation)
22342234

2235+
x, height, width, y, linewidth = np.broadcast_arrays(
2236+
# Make args iterable too.
2237+
np.atleast_1d(x), height, width, y, linewidth)
2238+
22352239
# lets do some conversions now since some types cannot be
22362240
# subtracted uniformly
22372241
if self.xaxis is not None:
2242+
x0 = x
22382243
x = self.convert_xunits(x)
2239-
width = self.convert_xunits(width)
2244+
try:
2245+
width = self.convert_xunits(x0 + width) - x
2246+
except TypeError:
2247+
width = self.convert_xunits(width)
22402248
if xerr is not None:
2241-
xerr = self.convert_xunits(xerr)
2249+
try:
2250+
xerr = self.convert_xunits(x0 + xerr) - x
2251+
except:
2252+
xerr = self.convert_xunits(xerr)
22422253

22432254
if self.yaxis is not None:
2255+
y0 = y
22442256
y = self.convert_yunits(y)
2245-
height = self.convert_yunits(height)
2257+
try:
2258+
height = self.convert_yunits(y0 + height) - y
2259+
except TypeError:
2260+
height = self.convert_yunits(height)
22462261
if yerr is not None:
2247-
yerr = self.convert_yunits(yerr)
2262+
try:
2263+
yerr = self.convert_yunits(y0 + yerr) - y
2264+
except:
2265+
yerr = self.convert_yunits(yerr)
22482266

2249-
x, height, width, y, linewidth = np.broadcast_arrays(
2250-
# Make args iterable too.
2251-
np.atleast_1d(x), height, width, y, linewidth)
22522267

22532268
# Now that units have been converted, set the tick locations.
22542269
if orientation == 'vertical':

0 commit comments

Comments
 (0)