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:0878eebb-4243-1828-bc9e-39bcf468bfc8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B97C:2088C9:1127F67:16F0E16:6A62C4E6 |
| html-safe-nonce | e29d493fd6ecf796cf2742545db98f406f0af77de50568c154b67df86cdc7006 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTdDOjIwODhDOToxMTI3RjY3OjE2RjBFMTY6NkE2MkM0RTYiLCJ2aXNpdG9yX2lkIjoiNjc4Njg1NjcyODIwOTMxMDk1MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 61e06c7e35f868b36fbfd693aee18629fcb8bc6580a4da10055bc8852bffea53 |
| 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 | df33b1b61ee7b9a0af988199bfc3503c9c1acafb1f1d40e1f140ea7c84f890dd |
| 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 | d41cd1bdb290013455c0ac430fa755621733f5eb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width