Remove old normalising code from plt.hist#9121
Conversation
| 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.
This is the old normalising code
| db = np.diff(bins) | ||
| m = (m.astype(float) / db) / m.sum() | ||
| if stacked: | ||
| if mlast is None: |
There was a problem hiding this comment.
This if statement is never used due to the same statement on line 6097
|
|
||
| @image_comparison(baseline_images=['hist_density'], extensions=['png']) | ||
| def test_hist_density(): | ||
| np.random.seed(0) |
There was a problem hiding this comment.
Can you use 19680801 (JDH's birthday) as the seed?
tacaswell
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.
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:
ntotopsto make the code more readable