Skip to content
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

Fix behavior of hist function when passed empty dataset #2551

Merged
merged 4 commits into from Jan 13, 2014

Conversation

neggert
Copy link
Contributor

@neggert neggert commented Oct 28, 2013

A colleague recently pointed out to me that the hist function is not well-behaved when it is passed an empty dataset. After this PR, we explicitly check for an empty dataset and throw a useful exception. The PR also allows the user to pass an empty dataset along with non-empty datasets, so that the empty dataset will show up on the legend. This is what my colleague was trying to do.

Incidentally, this PR makes the minimal changes possible to fix the problem. Many of these problems arise because of code that works around the issues with having a log-axis go all the way down to zero. Most of this code is no longer necessary because we added nonposy="clip" when setting the log scale. There's a chance that removing this code will slightly change how the axis limits are calculated, though, I want to target the removal at master.

@tacaswell
Copy link
Member

Can you add a test? I don't think it needs an image test, just a 'doesn't blow up' test.

@tacaswell
Copy link
Member

@neggert Can you add a test? It would be nice to get this into 1.4 which is coming up (very?) soon.

@neggert
Copy link
Contributor Author

neggert commented Jan 6, 2014

Done.

@@ -1162,6 +1162,11 @@ def test_hist_stacked_bar():
ax.hist(d, bins=10, histtype='barstacked', align='mid', color=colors, label=labels)
ax.legend(loc='upper right', bbox_to_anchor = (1.0, 1.0), ncol=1)

def test_hist_emptydata():
Copy link
Member

Choose a reason for hiding this comment

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

This should be "clearup"-ed.

tacaswell added a commit that referenced this pull request Jan 13, 2014
Fix behavior of hist function when passed empty dataset
@tacaswell tacaswell merged commit 45f5c45 into matplotlib:v1.3.x Jan 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants