Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7d9857f

Browse filesBrowse files
committed
FIX: Fix shape of hist output when input consists of multiple empty list.
1 parent 3ad9be2 commit 7d9857f
Copy full SHA for 7d9857f

File tree

Expand file treeCollapse file tree

3 files changed

+21
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-1
lines changed
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Modify output of Axes.hist when input consists of multiple empty lists
2+
``````````````````````````````````````````````````````````````````````
3+
4+
Input that consists of multiple empty lists will now return a list of histogram
5+
values for each one of the lists. For example, an input of ``[[],[]]`` will
6+
return 2 lists of histogram values. Previously, a single list was returned.

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6573,7 +6573,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65736573
# basic input validation
65746574
input_empty = np.size(x) == 0
65756575
# Massage 'x' for processing.
6576-
if input_empty:
6576+
if input_empty and len(x) == 0:
65776577
x = [np.array([])]
65786578
else:
65796579
x = cbook._reshape_2D(x, 'x')

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,20 @@ def test_hist_datetime_datasets():
16651665
ax.hist(data, stacked=False)
16661666

16671667

1668+
@pytest.mark.parametrize('data, expected_number_of_hists',
1669+
[([], 1),
1670+
([[]], 1),
1671+
([[], []], 2)])
1672+
def test_hist_with_empty_input(data, expected_number_of_hists):
1673+
hists, _, _ = plt.hist(data)
1674+
hists = np.asarray(hists)
1675+
1676+
if hists.ndim == 1:
1677+
assert 1 == expected_number_of_hists
1678+
else:
1679+
assert hists.shape[0] == expected_number_of_hists
1680+
1681+
16681682
def contour_dat():
16691683
x = np.linspace(-3, 5, 150)
16701684
y = np.linspace(-3, 5, 120)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.