🌐 AI搜索 & 代理 主页
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4507,7 +4507,7 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
Use a linear or log10 scale on the vertical axis.

mincnt : int > 0, default: *None*
If not *None*, only display cells with more than *mincnt*
If not *None*, only display cells with at least *mincnt*
number of points in the cell.

marginals : bool, default: *False*
Expand Down Expand Up @@ -4696,14 +4696,14 @@ def reduce_C_function(C: array) -> float
for i in range(nx1):
for j in range(ny1):
vals = lattice1[i, j]
if len(vals) > mincnt:
if len(vals) >= mincnt:
lattice1[i, j] = reduce_C_function(vals)
else:
lattice1[i, j] = np.nan
for i in range(nx2):
for j in range(ny2):
vals = lattice2[i, j]
if len(vals) > mincnt:
if len(vals) >= mincnt:
lattice2[i, j] = reduce_C_function(vals)
else:
lattice2[i, j] = np.nan
Expand Down
21 changes: 21 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,27 @@ def test_hexbin_log_clim():
assert h.get_clim() == (2, 100)


def test_hexbin_mincnt_withC():
# Issue #20877: Tests mincnt working the same with/without weights C
np.random.seed(19680801)
n = 20000

x = np.random.normal(loc=0, scale=2, size=n)
y = np.random.randint(0, 100, n)

fig, axes = plt.subplots(2, 1)

ax = axes[0]
res1 = ax.hexbin(x, y, mincnt=1, extent=[-8, 8, 0, 100], gridsize=150)

ax = axes[1]
res2 = ax.hexbin(x, y, mincnt=1, extent=[-8, 8, 0, 100], gridsize=150,
C=5*np.ones(len(x)), reduce_C_function=np.sum)

assert len(res1.get_array()) == len(res2.get_array())
assert 5*sum(res1.get_array()) == sum(res2.get_array())


def test_inverted_limits():
# Test gh:1553
# Calling invert_xaxis prior to plotting should not disable autoscaling
Expand Down