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

Fix ValueError being raised when plotting hist and hexbin on empty dataset (Fix #3886) #4119

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 7 commits into from
Mar 30, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix hist raising ValueError on empty dataset
  • Loading branch information
Umair Idris committed Feb 17, 2015
commit 287a815f4ac96c93f2bf82b46257b1d4aaa5e21a
2 changes: 2 additions & 0 deletions 2 lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5605,6 +5605,8 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,

# basic input validation
flat = np.ravel(x)
if len(flat) == 0:
return [], [], cbook.silent_list('No Patches')
Copy link
Member

Choose a reason for hiding this comment

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

Do we want do draw no patches or patches of zero size? On consideration I think patches of zero size might be a better option here so client code which expects a non-zero length list does not have to check that it is true. For example if the user passes in bin edges, they should get back a list of zeros telling them that there are no counts in any of the bins.

Copy link
Member

Choose a reason for hiding this comment

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

@efiring @mdboom @WeatherGod @pelson Thoughts, I think that this is an important API choice that needs to be made.


# Massage 'x' for processing.
# NOTE: Be sure any changes here is also done below to 'weights'
Expand Down
3 changes: 3 additions & 0 deletions 3 lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,9 @@ def test_hist_log():
ax.hist(data, fill=False, log=True)


def test_hist_empty():
ax.hist([])
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as for the other test.

Copy link
Author

Choose a reason for hiding this comment

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

Done.


@image_comparison(baseline_images=['hist_steplog'], remove_text=True)
def test_hist_steplog():
np.random.seed(0)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.