Skip to content

swev-id: matplotlib__matplotlib-26113 — Align hexbin mincnt behavior with and without C (>= mincnt)#65

Open
casey-brooks wants to merge 2 commits intomatplotlib__matplotlib-26113from
fix/hexbin-mincnt-parity-26113
Open

swev-id: matplotlib__matplotlib-26113 — Align hexbin mincnt behavior with and without C (>= mincnt)#65
casey-brooks wants to merge 2 commits intomatplotlib__matplotlib-26113from
fix/hexbin-mincnt-parity-26113

Conversation

@casey-brooks
Copy link

Summary

  • set the C-aware hexbin path to treat mincnt=None as 1 and require len(acc) >= mincnt
  • update the mincnt docstring to describe the "at least" threshold
  • add focused regression tests covering parity between count- and C-based binning

Issue

Fixes #63

Reproduction

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
x = np.array([0.1, 1.6])
y = np.array([0.1, 1.6])

print(ax.hexbin(x, y, gridsize=(2, 2), extent=(0, 2, 0, 2), mincnt=1).get_array())
print(ax.hexbin(x, y, C=np.ones_like(x), gridsize=(2, 2), extent=(0, 2, 0, 2), mincnt=1, reduce_C_function=np.sum).get_array())

Observed Behavior

  • Without C, the bin counts were returned when population size was >= mincnt.
  • With C, bins of size exactly equal to mincnt were dropped because the reducer only ran on len(acc) > mincnt.

Expected Behavior

  • Both code paths should emit bins whenever the population length meets or exceeds mincnt.

Testing

  • MPLBACKEND=Agg PYTHONPATH=/workspace/matplotlib/lib LD_LIBRARY_PATH=/root/.nix-profile/lib .venv/bin/pytest -q lib/matplotlib/tests/test_axes.py -k hexbin
  • MPLBACKEND=Agg PYTHONPATH=/workspace/matplotlib/lib LD_LIBRARY_PATH=/root/.nix-profile/lib .venv/bin/flake8 lib/matplotlib/axes/_axes.py lib/matplotlib/tests/test_axes.py --extend-ignore=E721

@casey-brooks casey-brooks requested a review from a team December 25, 2025 13:07
@casey-brooks
Copy link
Author

Test & Lint Summary

  • .......... [100%]
    10 passed, 871 deselected in 1.03s → 10 passed, 871 deselected
  • → no lint errors (E721 ignored due to existing file-level violations)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates—this gets the parity story close. I did spot one regression: with mincnt=0 we now run the reducer on empty accumulators, which warns or raises for many reducers (including the default np.mean). Could you restore a guard so we never invoke reduce_C_function on an empty list?

@casey-brooks
Copy link
Author

Test & Lint Summary (update)

  • ........... [100%]
    11 passed, 871 deselected in 1.03s → 11 passed, 871 deselected
  • → no lint errors (E721 ignored due to existing file-level violations)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard now keeps reduce_C_function away from empty accumulators, and the new regression test locks the mincnt=0 parity in place. Looks good to me—thanks for the quick follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants