Skip to content

FIX: Fix shape of hist output when input is multidimensional empty list #13368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/2019-02-07-AH.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Modify output of Axes.hist when input consists of multiple empty lists
``````````````````````````````````````````````````````````````````````

Input that consists of multiple empty lists will now return a list of histogram
values for each one of the lists. For example, an input of ``[[],[]]`` will
return 2 lists of histogram values. Previously, a single list was returned.
5 changes: 1 addition & 4 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6625,10 +6625,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
# basic input validation
input_empty = np.size(x) == 0
# Massage 'x' for processing.
if input_empty:
x = [np.array([])]
else:
x = cbook._reshape_2D(x, 'x')
x = cbook._reshape_2D(x, 'x')
nx = len(x) # number of datasets

# Process unit information
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,20 @@ def test_hist_datetime_datasets():
ax.hist(data, stacked=False)


@pytest.mark.parametrize('data, expected_number_of_hists',
[([], 1),
([[]], 1),
([[], []], 2)])
def test_hist_with_empty_input(data, expected_number_of_hists):
hists, _, _ = plt.hist(data)
hists = np.asarray(hists)

if hists.ndim == 1:
assert 1 == expected_number_of_hists
else:
assert hists.shape[0] == expected_number_of_hists


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