Title: hexbin passes empty bins to reduce_C_function when mincnt is 0 or None · Issue #32077 · matplotlib/matplotlib · GitHub
Open Graph Title: hexbin passes empty bins to reduce_C_function when mincnt is 0 or None · Issue #32077 · matplotlib/matplotlib
X Title: hexbin passes empty bins to reduce_C_function when mincnt is 0 or None · Issue #32077 · matplotlib/matplotlib
Description: Bug summary Empty bins are passed to the C reducer when mincnt is zero or None. This causes reducers such as np.sum to produce spurious zero-valued bins, while custom reducers may raise an exception. Code for reproduction import numpy as...
Open Graph Description: Bug summary Empty bins are passed to the C reducer when mincnt is zero or None. This causes reducers such as np.sum to produce spurious zero-valued bins, while custom reducers may raise an exceptio...
X Description: Bug summary Empty bins are passed to the C reducer when mincnt is zero or None. This causes reducers such as np.sum to produce spurious zero-valued bins, while custom reducers may raise an exceptio...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/32077
X: @github
Domain: Github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"hexbin passes empty bins to reduce_C_function when mincnt is 0 or None","articleBody":"### Bug summary\n\nEmpty bins are passed to the C reducer when `mincnt` is zero or `None`. This causes reducers such as `np.sum` to produce spurious zero-valued bins, while custom reducers may raise an exception.\n\n### Code for reproduction\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nx = [0.25]\ny = [0.25]\nc = [3.0]\nmincnt = 0\n\ndef reject_empty(values):\n if len(values) == 0:\n raise ValueError(\"empty bin passed to reducer\")\n return float(np.sum(values))\n\nprint(\"Inputs:\", {\"x\": x, \"y\": y, \"C\": c, \"mincnt\": mincnt})\ntry:\n fig, ax = plt.subplots()\n collection = ax.hexbin(\n x, y, C=c, gridsize=3, extent=(0, 1, 0, 1),\n reduce_C_function=reject_empty, mincnt=mincnt\n )\n print(\"Bin offsets:\", collection.get_offsets().tolist())\n print(\"Reduced values:\", collection.get_array().tolist())\n plt.close(fig)\nexcept Exception as exc:\n print(str(exc))\n```\n\n### Actual outcome\n\n```text\nInputs: {'x': [0.25], 'y': [0.25], 'C': [3.0], 'mincnt': 0}\nempty bin passed to reducer\n```\n\n### Expected outcome\n\nEmpty bins should not be passed to `reduce_C_function`. The output should contain only the non-empty bin:\n\n```text\nInputs: {'x': [0.25], 'y': [0.25], 'C': [3.0], 'mincnt': 0}\nBin offsets: [[0.333333333, 0.0]]\nReduced values: [3.0]\n```\n\n### Additional information\n\nThis is a regression introduced by PR #26113: https://github.com/matplotlib/matplotlib/pull/26113\n\nThe bin-inclusion condition was changed from `count \u003e mincnt` to `count \u003e= mincnt`. Consequently, zero-count bins are processed when `mincnt` is `0`. When `C` is provided and `mincnt` is `None`, it is internally set to `0`, producing the same behavior. Reducers such as `np.sum` return spurious zero-valued bins for empty inputs, while custom reducers may raise an exception.\n\n### Operating system\n\nLinux\n\n### Matplotlib Version\n\n3.11.1\n\n### Matplotlib Backend\n\nagg\n\n### Python version\n\n3.11.13\n\n### Jupyter version\n\nN/A\n\n### Installation\n\nN/A","author":{"url":"https://github.com/SuYanqi","@type":"Person","name":"SuYanqi"},"datePublished":"2026-07-20T10:07:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/32077/matplotlib/issues/32077"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:23a39165-6d6e-12d0-083c-f4e5ec182511 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CA8E:1C0181:813C40:AED0F5:6A628367 |
| html-safe-nonce | c7869ebdc2cd51aba801850ae4405f8016ac29c3aff4a73a38f014ceae116d5f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQThFOjFDMDE4MTo4MTNDNDA6QUVEMEY1OjZBNjI4MzY3IiwidmlzaXRvcl9pZCI6IjE0NTMyMDUwOTgzNzQyNjc3NTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 749bf2ec8de79cf9db6cca2f2aa6e848d1a65f6ca2924bc624f818764ec25102 |
| hovercard-subject-tag | issue:4927903079 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/32077/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8b91b2b6f2384e73854c90c1f9ba90a765e6001286efe3a0e85b916b62bedb87/matplotlib/matplotlib/issues/32077 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8b91b2b6f2384e73854c90c1f9ba90a765e6001286efe3a0e85b916b62bedb87/matplotlib/matplotlib/issues/32077 |
| og:image:alt | Bug summary Empty bins are passed to the C reducer when mincnt is zero or None. This causes reducers such as np.sum to produce spurious zero-valued bins, while custom reducers may raise an exceptio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SuYanqi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7a4ef49a11a2c05de16a801b29c54a151d2e3262d6fd17381ca13b5ae25dda8f |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 97b18c8f1d2683a31995fd6e802daf9bf0d4d3f0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width