diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 6edf7fb46e4f..ad40cab3ea6b 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -6732,7 +6732,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 130a40557426..679220547a6c 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -6367,3 +6367,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