Title: [Bug]: integer colours for pcolorfast / quadmesh · Issue #22236 · matplotlib/matplotlib · GitHub
Open Graph Title: [Bug]: integer colours for pcolorfast / quadmesh · Issue #22236 · matplotlib/matplotlib
X Title: [Bug]: integer colours for pcolorfast / quadmesh · Issue #22236 · matplotlib/matplotlib
Description: Bug summary I get an error ValueError: RGBA values should be within 0-1 range when passing a byte/integer array to pcolorfast to code the colors as RGBA. It also fails when data type is uint8 Code for reproduction import numpy as np impo...
Open Graph Description: Bug summary I get an error ValueError: RGBA values should be within 0-1 range when passing a byte/integer array to pcolorfast to code the colors as RGBA. It also fails when data type is uint8 Code ...
X Description: Bug summary I get an error ValueError: RGBA values should be within 0-1 range when passing a byte/integer array to pcolorfast to code the colors as RGBA. It also fails when data type is uint8 Code ...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22236
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: integer colours for pcolorfast / quadmesh","articleBody":"### Bug summary\r\n\r\nI get an error \r\n```\r\nValueError: RGBA values should be within 0-1 range\r\n```\r\nwhen passing a byte/integer array to pcolorfast to code the colors as RGBA. It also fails when data type is `uint8` \r\n\r\n### Code for reproduction\r\n\r\n```python\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.cm import get_cmap\r\ncmap = get_cmap('bwr_r'')\r\nfig, ax = plt.subplots()\r\nx, y = np.mgrid[0:10:100j, 0:10:100j]\r\nv = np.abs(np.sin(x) * np.cos(y))\r\nc = (cmap(v[:-1, :-1]) * 255).astype(np.int64)\r\nax.pcolorfast(x, y, c)\r\n```\r\n\r\n\r\n### Actual outcome\r\n\r\n```\r\nValueError: RGBA values should be within 0-1 range\r\n```\r\n\r\n### Expected outcome\r\n\r\na plot in in some bluish colour\r\n\r\n### Additional information\r\n\r\nfixes:\r\n\r\n1) in `colors.py`, line 321:\r\n```\r\nif (isinstance(c, np.ndarray) and c.dtype.kind in \"if\"\r\n```\r\nshould be replaced by\r\n```\r\nif (isinstance(c, np.ndarray) and c.dtype.kind in \"ifu\"\r\n```\r\nto allow for unsigned int values as well\r\n\r\n2) in line 343:\r\n```\r\n if np.any((result \u003c 0) | (result \u003e 1)):\r\n raise ValueError(\"RGBA values should be within 0-1 range\")\r\n```\r\nshould be replaced by a test including dtype.kind - for 'i' and 'u'. \r\nIt may be sufficient to comment it out as a quick fix as it is definitively more broken having it in.\r\n\r\n ```\r\n if c.dtype.kind in \"f\" and np.any((result \u003c 0) | (result \u003e 1)):\r\n raise ValueError(\"RGBA float values should be within 0-1 range\")\r\n if c.dtype.kind in \"ui\" and np.any((result \u003c 0) | (result \u003e 255)):\r\n raise ValueError(\"RGBA fixed values should be within 0-255 range\")\r\n```\r\neven with this it does not quite work\r\n\r\n### Operating system\r\n\r\n 5.15.13-200.fc35.x86_64\r\n\r\n### Matplotlib Version\r\n\r\n3.5.1\r\n\r\n### Matplotlib Backend\r\n\r\ngtk3\r\n\r\n### Python version\r\n\r\n3.10.1\r\n\r\n### Jupyter version\r\n\r\n8.0.0\r\n\r\n### Installation\r\n\r\npip","author":{"url":"https://github.com/2sn","@type":"Person","name":"2sn"},"datePublished":"2022-01-15T06:20:29.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/22236/matplotlib/issues/22236"}
| 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:6c4a2a5f-4ddb-a5ba-a504-31956542ac2c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C98:171DD4:19625CD:21C1B71:6A52C0DF |
| html-safe-nonce | 8dd69f326f6fa521ace0657420f0988f0127b78a34579a203fde17932d6acde9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Qzk4OjE3MURENDoxOTYyNUNEOjIxQzFCNzE6NkE1MkMwREYiLCJ2aXNpdG9yX2lkIjoiNDcwMDE0NTUzMTcxMTgzMjI4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | afa7a7331751e5c3f249650d817f7c2245b92ee7a24348852e9cbee036800cbe |
| hovercard-subject-tag | issue:1104516884 |
| 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/22236/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9c8af463da7f663fc0f81b0055739f26f35b807866b5112823cb07cff47a6e6f/matplotlib/matplotlib/issues/22236 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9c8af463da7f663fc0f81b0055739f26f35b807866b5112823cb07cff47a6e6f/matplotlib/matplotlib/issues/22236 |
| og:image:alt | Bug summary I get an error ValueError: RGBA values should be within 0-1 range when passing a byte/integer array to pcolorfast to code the colors as RGBA. It also fails when data type is uint8 Code ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | 2sn |
| 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 | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width