Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5879,7 +5879,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
Parameters
----------
x : (n,) array or sequence of (n,) arrays
Input values, this takes either a single array or a sequency of
Input values, this takes either a single array or a sequence of
arrays which are not required to be of the same length

bins : integer or sequence or 'auto', optional
Expand Down Expand Up @@ -6091,30 +6091,31 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
"Please only use 'density', since 'normed'"
"will be deprecated.")

# process the unit information
self._process_unit_info(xdata=x, kwargs=kwargs)
x = self.convert_xunits(x)
if bin_range is not None:
bin_range = self.convert_xunits(bin_range)

# Check whether bins or range are given explicitly.
binsgiven = (cbook.iterable(bins) or bin_range is not None)

# basic input validation
input_empty = np.size(x) == 0

# Massage 'x' for processing.
if input_empty:
x = np.array([[]])
x = [np.array([[]])]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many square brackets--I think this should be a list with one empty 1-D array, not with an empty 2-D array.

else:
x = cbook._reshape_2D(x, 'x')
nx = len(x) # number of datasets

# Process unit information
# Unit conversion is done individually on each dataset
self._process_unit_info(xdata=x[0], kwargs=kwargs)
x = [self.convert_xunits(xi) for xi in x]

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

# Check whether bins or range are given explicitly.
binsgiven = (cbook.iterable(bins) or bin_range is not None)

# We need to do to 'weights' what was done to 'x'
if weights is not None:
w = cbook._reshape_2D(weights, 'weights')
else:
w = [None]*nx
w = [None] * nx

if len(w) != nx:
raise ValueError('weights should have the same shape as x')
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,14 @@ def test_hist_unequal_bins_density():
assert_allclose(mpl_heights, np_heights)


def test_hist_datetime_datasets():
data = [[datetime.datetime(2017, 1, 1), datetime.datetime(2017, 1, 1)],
[datetime.datetime(2017, 1, 1), datetime.datetime(2017, 1, 2)]]
fig, ax = plt.subplots()
ax.hist(data, stacked=True)
ax.hist(data, stacked=False)


def contour_dat():
x = np.linspace(-3, 5, 150)
y = np.linspace(-3, 5, 120)
Expand Down