Skip to content

Commit 653be4e

Browse files
committed
Add description about density and tests
1 parent d063002 commit 653be4e

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6878,6 +6878,9 @@ def hist2d(self, x, y, bins=10, range=None, density=None, weights=None,
68786878
keyword argument. Likewise, power-law normalization (similar
68796879
in effect to gamma correction) can be accomplished with
68806880
`.colors.PowerNorm`.
6881+
- Numpy 1.15 introduced a 'density' kwarg to hist2d. Even though
6882+
Numpy 1.15 isn't required, 'density' kwarg is introduced
6883+
and passed as 'normed' to ``hist2d``.
68816884
"""
68826885

68836886
if density is not None and normed is not None:

lib/matplotlib/tests/test_axes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,30 @@ def test_hist2d():
16721672
ax.hist2d("x", "y", bins=10, data=data, rasterized=True)
16731673

16741674

1675+
@pytest.mark.parametrize('density', [False, True])
1676+
def test_hist2d_density(density):
1677+
# Test density kwarg
1678+
x = np.random.randn(100)*2+5
1679+
y = np.random.randn(100)-2
1680+
fig = plt.figure()
1681+
ax = fig.add_subplot(111)
1682+
ax.hist2d(x, y, bins=10, rasterized=True, density=density)
1683+
1684+
1685+
@pytest.mark.parametrize('normed', [False, True])
1686+
@pytest.mark.parametrize('density', [False, True])
1687+
def test_hist2d_normed_density(density, normed):
1688+
# Normed and density should not be used simultaneously
1689+
x = np.random.randn(100)*2+5
1690+
y = np.random.randn(100)-2
1691+
fig = plt.figure()
1692+
ax = fig.add_subplot(111)
1693+
# test that kwargs normed and density cannot be set both.
1694+
with pytest.raises(ValueError, match="kwargs 'density' and 'normed'"):
1695+
ax.hist2d(x, y, bins=10, rasterized=True,
1696+
density=density, normed=normed)
1697+
1698+
16751699
@image_comparison(baseline_images=['hist2d_transpose'],
16761700
remove_text=True, style='mpl20')
16771701
def test_hist2d_transpose():

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy