From a06f25e58dd453f8776b1cf411af5c371ff0789e Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 18 Apr 2019 21:46:51 -0400 Subject: [PATCH] FIX: update not replace hist_kwargs when density is passed closes #13982 --- lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/tests/test_axes.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 4b73d5229384..bc5461ad9f22 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6686,7 +6686,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, density = bool(density) or bool(normed) if density and not stacked: - hist_kwargs = dict(density=density) + hist_kwargs['density'] = density # List to store all the top coordinates of the histograms tops = [] diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index cff4325f1936..b72c47839856 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6369,3 +6369,10 @@ def test_hist_nan_data(): assert np.allclose(bins, nanbins) assert np.allclose(edges, nanedges) + + +def test_hist_range_and_density(): + _, bins, _ = plt.hist(np.random.rand(10), "auto", + range=(0, 1), density=True) + assert bins[0] == 0 + assert bins[-1] == 1