-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Remove old normalising code from plt.hist #9121
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
Conversation
for i in xrange(nx): | ||
# this will automatically overwrite bins, | ||
# so that each histogram uses the same bins | ||
m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs) | ||
m = m.astype(float) # causes problems later if it's an int | ||
if mlast is None: | ||
mlast = np.zeros(len(bins)-1, m.dtype) | ||
if density and not stacked: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the old normalising code
if stacked: | ||
if mlast is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This if statement is never used due to the same statement on line 6097
lib/matplotlib/tests/test_axes.py
Outdated
@@ -1464,6 +1464,14 @@ def test_hist_step_filled(): | |||
assert all([p.get_facecolor() == p.get_edgecolor() for p in patches]) | |||
|
|||
|
|||
@image_comparison(baseline_images=['hist_density'], extensions=['png']) | |||
def test_hist_density(): | |||
np.random.seed(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use 19680801 (JDH's birthday) as the seed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modulo changing the seed and squashing the image changes.
83da06e
to
2dde48a
Compare
np.random.seed(19680801) | ||
data = np.random.standard_normal(2000) | ||
fig, ax = plt.subplots() | ||
ax.hist(data, density=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually need an image test, or can we just test that np.histogram
properly applies the density kwarg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there was ever any image test that used the 'density' or 'norm' kwargs
, so I thought it would be a good idea to add one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we are trying to keep image tests to things where the actual image appearance might change if code changes. So sure if there is no hist image test there should be one. If such a test does exist then this just tests the value of the bars, and I think you can do that w/o an image comparison. But I’m not passionate about it or anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beating a dead horse, but:
np.random.seed(19680801)
data = np.random.standard_normal(2000)
fig, ax = plt.subplots()
n, bins, patches = ax.hist(data, density=True)
assert np.isclose(np.sum(n * np.diff(bins)), 1.0)
@meeseeksdev backport to v2.1.x |
Backport PR #9121 on branch v2.1.x
This PR does a few things:
n
totops
to make the code more readable