From 53fad8551bd179fc4d32a0c3dd5b9e71afca257c Mon Sep 17 00:00:00 2001 From: Jake VanderPlas Date: Tue, 24 Oct 2017 12:31:21 -0700 Subject: [PATCH 1/2] TST: add test of normed histogram with unequal bins --- lib/matplotlib/tests/test_axes.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index f6e92b70c6ac..62802fc9a70e 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1565,6 +1565,17 @@ def test_hist_step_log_bottom(): ax.set_ylim(9e-3, 1e3) +def test_hist_unequal_bins_normed(): + # Test correct behavior of normalized histogram with unequal bins + # https://github.com/matplotlib/matplotlib/issues/9557 + rng = np.random.RandomState(57483) + t = rng.randn(100) + bins = [-3, -1, -0.5, 0, 1, 5] + mpl_heights, _, _ = plt.hist(t, bins=bins, normed=True) + np_heights, _ = np.histogram(t, bins=bins, density=True) + assert_allclose(mpl_heights, np_heights) + + def contour_dat(): x = np.linspace(-3, 5, 150) y = np.linspace(-3, 5, 120) From 7b3374ac81485a439fcf0afc5bb4ef67bb15a290 Mon Sep 17 00:00:00 2001 From: Jake VanderPlas Date: Tue, 24 Oct 2017 17:12:47 -0700 Subject: [PATCH 2/2] TST: normed->density --- lib/matplotlib/tests/test_axes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 62802fc9a70e..69e056140ea0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -1565,13 +1565,13 @@ def test_hist_step_log_bottom(): ax.set_ylim(9e-3, 1e3) -def test_hist_unequal_bins_normed(): +def test_hist_unequal_bins_density(): # Test correct behavior of normalized histogram with unequal bins # https://github.com/matplotlib/matplotlib/issues/9557 rng = np.random.RandomState(57483) t = rng.randn(100) bins = [-3, -1, -0.5, 0, 1, 5] - mpl_heights, _, _ = plt.hist(t, bins=bins, normed=True) + mpl_heights, _, _ = plt.hist(t, bins=bins, density=True) np_heights, _ = np.histogram(t, bins=bins, density=True) assert_allclose(mpl_heights, np_heights)