Skip to content

Commit 221a218

Browse files
committed
Do unit conversion even if stacked isn't true
1 parent c02a84d commit 221a218

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6095,20 +6095,15 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
60956095
input_empty = np.size(x) == 0
60966096
# Massage 'x' for processing.
60976097
if input_empty:
6098-
x = np.array([[]])
6098+
x = [np.array([[]])]
60996099
else:
61006100
x = cbook._reshape_2D(x, 'x')
61016101
nx = len(x) # number of datasets
61026102

61036103
# Process unit information
6104-
# If doing a stacked histogram, the input is a list of datasets, so
6105-
# we need to do the unit conversion individually on each dataset
6106-
if stacked:
6107-
self._process_unit_info(xdata=x[0], kwargs=kwargs)
6108-
x = [self.convert_xunits(xi) for xi in x]
6109-
else:
6110-
self._process_unit_info(xdata=x, kwargs=kwargs)
6111-
x = self.convert_xunits(x)
6104+
# Unit conversion is done individually on each dataset
6105+
self._process_unit_info(xdata=x[0], kwargs=kwargs)
6106+
x = [self.convert_xunits(xi) for xi in x]
61126107

61136108
if bin_range is not None:
61146109
bin_range = self.convert_xunits(bin_range)

lib/matplotlib/tests/test_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1576,11 +1576,12 @@ def test_hist_unequal_bins_density():
15761576
assert_allclose(mpl_heights, np_heights)
15771577

15781578

1579-
def test_hist_stacked_datetime():
1579+
def test_hist_datetime_datasets():
15801580
data = [[datetime.datetime(2017, 1, 1), datetime.datetime(2017, 1, 1)],
15811581
[datetime.datetime(2017, 1, 1), datetime.datetime(2017, 1, 2)]]
15821582
fig, ax = plt.subplots()
15831583
ax.hist(data, stacked=True)
1584+
ax.hist(data, stacked=False)
15841585

15851586

15861587
def contour_dat():

0 commit comments

Comments
 (0)