Skip to content

Commit 9f891c6

Browse files
authored
Merge pull request #13989 from tacaswell/fix_hist_range_and_density
FIX: update not replace hist_kwargs when density is passed
2 parents a3e2897 + a06f25e commit 9f891c6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6686,7 +6686,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
66866686

66876687
density = bool(density) or bool(normed)
66886688
if density and not stacked:
6689-
hist_kwargs = dict(density=density)
6689+
hist_kwargs['density'] = density
66906690

66916691
# List to store all the top coordinates of the histograms
66926692
tops = []

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6369,3 +6369,10 @@ def test_hist_nan_data():
63696369

63706370
assert np.allclose(bins, nanbins)
63716371
assert np.allclose(edges, nanedges)
6372+
6373+
6374+
def test_hist_range_and_density():
6375+
_, bins, _ = plt.hist(np.random.rand(10), "auto",
6376+
range=(0, 1), density=True)
6377+
assert bins[0] == 0
6378+
assert bins[-1] == 1

0 commit comments

Comments
 (0)