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 09b2b0d

Browse filesBrowse files
authored
Merge pull request #13368 from hershen/empty_hist_with_colors
FIX: Fix shape of hist output when input is multidimensional empty list
2 parents 95c583a + 45f29b7 commit 09b2b0d
Copy full SHA for 09b2b0d

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+21
-4
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-4Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6625,10 +6625,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
66256625
# basic input validation
66266626
input_empty = np.size(x) == 0
66276627
# Massage 'x' for processing.
6628-
if input_empty:
6629-
x = [np.array([])]
6630-
else:
6631-
x = cbook._reshape_2D(x, 'x')
6628+
x = cbook._reshape_2D(x, 'x')
66326629
nx = len(x) # number of datasets
66336630

66346631
# Process unit information

‎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
@@ -1666,6 +1666,20 @@ def test_hist_datetime_datasets():
16661666
ax.hist(data, stacked=False)
16671667

16681668

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