Title: [Bug]: Hexbin with bins='log' doesn't handle zeros as described · Issue #30764 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: Hexbin with bins='log' doesn't handle zeros as described · Issue #30764 · matplotlib/matplotlib
X Title: [Bug]: Hexbin with bins='log' doesn't handle zeros as described · Issue #30764 · matplotlib/matplotlib
Description: Bug summary The hexbin documentation for the bins parameter says "If 'log', use a logarithmic scale for the colormap. Internally, log_10(i+1) is used to determine the hexagon color. This is equivalent to norm=LogNorm()." My understanding...
Open Graph Description: Bug summary The hexbin documentation for the bins parameter says "If 'log', use a logarithmic scale for the colormap. Internally, log_10(i+1) is used to determine the hexagon color. This is equival...
X Description: Bug summary The hexbin documentation for the bins parameter says "If 'log', use a logarithmic scale for the colormap. Internally, log_10(i+1) is used to determine the hexagon color. Th...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30764
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: Hexbin with bins='log' doesn't handle zeros as described","articleBody":"### Bug summary\n\nThe `hexbin` documentation for the `bins` parameter says \"If 'log', use a logarithmic scale for the colormap. Internally, log_10(i+1) is used to determine the hexagon color. This is equivalent to norm=LogNorm().\" My understanding is that by using i+1 as the scaling, any bins with zero points in them should be mapped to log(1) = 0 and appear with the bottom color of the colorbar. Instead, these zero bins appear to be mapped to log(0) and appear as the \"bad\" color.\n\n### Code for reproduction\n\n```Python\nimport numpy as np\nimport matplotlib.pyplot as plt\n\nnp.random.seed(1)\nxs = np.random.random(100)\nys = np.random.random(100)\nplt.hexbin(xs, ys, bins='log', gridsize=10)\nplt.colorbar()\n```\n\n### Actual outcome\n\n\u003cimg width=\"587\" height=\"453\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/54e8bf16-8a88-4e2d-a80f-3d40e2b64f9a\" /\u003e\n\n### Expected outcome\n\nI would expect the output to look like this (though for this hacked-up example the colorbar tick labels leave something to be desired.\n`plt.hexbin(xs, ys, gridsize=10, C=C, reduce_C_function=lambda x: np.log10(1 + np.sum(x)), mincnt=-1)`\n\n\u003cimg width=\"548\" height=\"436\" alt=\"Image\" src=\"https://github.com/user-attachments/assets/7fb10f36-135c-4c02-9be8-6de88f9842c5\" /\u003e\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nUbuntu\n\n### Matplotlib Version\n\n3.10.7\n\n### Matplotlib Backend\n\nqtagg\n\n### Python version\n\n3.12.8\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\npip","author":{"url":"https://github.com/svank","@type":"Person","name":"svank"},"datePublished":"2025-11-18T17:57:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/30764/matplotlib/issues/30764"}
| 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:c29cfe99-9a0e-f10f-2198-99de3439979c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C816:2BEA70:9C62DA:D493FF:6A5200D7 |
| html-safe-nonce | b94012ed33c5cdaeacfb24ec951b6a57ba47f99f9e176515e3a66154a191c6a8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODE2OjJCRUE3MDo5QzYyREE6RDQ5M0ZGOjZBNTIwMEQ3IiwidmlzaXRvcl9pZCI6Ijc5MTk0NjM5Mzk0NDgxMTEzMTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2a11e12c915b584f0f026e203fac847cab06c6948997c7ad786f28063600ec7a |
| hovercard-subject-tag | issue:3639353081 |
| 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/30764/issue_layout |
| twitter:image | https://opengraph.githubassets.com/34b405fb331c3560cef93db9d06542c9153d8e6254bbe460755c04429dfaac38/matplotlib/matplotlib/issues/30764 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/34b405fb331c3560cef93db9d06542c9153d8e6254bbe460755c04429dfaac38/matplotlib/matplotlib/issues/30764 |
| og:image:alt | Bug summary The hexbin documentation for the bins parameter says "If 'log', use a logarithmic scale for the colormap. Internally, log_10(i+1) is used to determine the hexagon color. This is equival... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | svank |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| 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 | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width