Title: Floating point image RGB values must be in the 0..1 range · Issue #10372 · matplotlib/matplotlib · GitHub
Open Graph Title: Floating point image RGB values must be in the 0..1 range · Issue #10372 · matplotlib/matplotlib
X Title: Floating point image RGB values must be in the 0..1 range · Issue #10372 · matplotlib/matplotlib
Description: Bug report Bug summary From matplorlib 2.0 to 2.1 this problem appeared: Floating point image RGB values must be in the 0..1 range, instead of producing an image with noise on it. Code for reproduction Can use any image to try to reprodu...
Open Graph Description: Bug report Bug summary From matplorlib 2.0 to 2.1 this problem appeared: Floating point image RGB values must be in the 0..1 range, instead of producing an image with noise on it. Code for reproduc...
X Description: Bug report Bug summary From matplorlib 2.0 to 2.1 this problem appeared: Floating point image RGB values must be in the 0..1 range, instead of producing an image with noise on it. Code for reproduc...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/10372
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Floating point image RGB values must be in the 0..1 range","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\nFrom matplorlib 2.0 to 2.1 this problem appeared: Floating point image RGB values must be in the 0..1 range, instead of producing an image with noise on it.\r\n\r\n**Code for reproduction**\r\nCan use any image to try to reproduce this problem:\r\n\r\n```python\r\nimport imageio\r\nimport numpy as np\r\nfrom matplotlib.pyplot import imshow\r\n%matplotlib inline\r\n\r\nimage_file=\"image.jpg\"\r\ncontent_image = imageio.imread(image_file)\r\n#imshow(content_image)\r\n\r\nnoise_ratio = 0.6\r\nimage_height, image_width, color_channels = content_image.shape\r\nnoise_image = np.random.uniform(-20, 20, (1, image_height, image_width, color_channels)).astype('float32')\r\ninput_image = noise_image * noise_ratio + content_image * (1 - noise_ratio)\r\nimshow(input_image[0])\r\n```\r\n\r\n**Actual outcome**\r\n```\r\n\u003cmatplotlib.image.AxesImage at 0x7fad8700b748\u003e\r\nError in callback \u003cfunction install_repl_displayhook.\u003clocals\u003e.post_execute at 0x7fad44bbb510\u003e (for post_execute):\r\n---------------------------------------------------------------------------\r\nValueError Traceback (most recent call last)\r\n~/.local/lib/python3.5/site-packages/matplotlib/pyplot.py in post_execute()\r\n 147 def post_execute():\r\n 148 if matplotlib.is_interactive():\r\n--\u003e 149 draw_all()\r\n 150 \r\n 151 # IPython \u003e= 2\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/_pylab_helpers.py in draw_all(cls, force)\r\n 134 for f_mgr in cls.get_all_fig_managers():\r\n 135 if force or f_mgr.canvas.figure.stale:\r\n--\u003e 136 f_mgr.canvas.draw_idle()\r\n 137 \r\n 138 atexit.register(Gcf.destroy_all)\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/backend_bases.py in draw_idle(self, *args, **kwargs)\r\n 2053 if not self._is_idle_drawing:\r\n 2054 with self._idle_draw_cntx():\r\n-\u003e 2055 self.draw(*args, **kwargs)\r\n 2056 \r\n 2057 def draw_cursor(self, event):\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in draw(self)\r\n 429 # if toolbar:\r\n 430 # toolbar.set_cursor(cursors.WAIT)\r\n--\u003e 431 self.figure.draw(self.renderer)\r\n 432 finally:\r\n 433 # if toolbar:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n 53 renderer.start_filter()\r\n 54 \r\n---\u003e 55 return draw(artist, renderer, *args, **kwargs)\r\n 56 finally:\r\n 57 if artist.get_agg_filter() is not None:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/figure.py in draw(self, renderer)\r\n 1473 \r\n 1474 mimage._draw_list_compositing_images(\r\n-\u003e 1475 renderer, self, artists, self.suppressComposite)\r\n 1476 \r\n 1477 renderer.close_group('figure')\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\r\n 136 if not_composite or not has_images:\r\n 137 for a in artists:\r\n--\u003e 138 a.draw(renderer)\r\n 139 else:\r\n 140 # Composite any adjacent images together\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n 53 renderer.start_filter()\r\n 54 \r\n---\u003e 55 return draw(artist, renderer, *args, **kwargs)\r\n 56 finally:\r\n 57 if artist.get_agg_filter() is not None:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)\r\n 2579 renderer.stop_rasterizing()\r\n 2580 \r\n-\u003e 2581 mimage._draw_list_compositing_images(renderer, self, artists)\r\n 2582 \r\n 2583 renderer.close_group('axes')\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\r\n 136 if not_composite or not has_images:\r\n 137 for a in artists:\r\n--\u003e 138 a.draw(renderer)\r\n 139 else:\r\n 140 # Composite any adjacent images together\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n 53 renderer.start_filter()\r\n 54 \r\n---\u003e 55 return draw(artist, renderer, *args, **kwargs)\r\n 56 finally:\r\n 57 if artist.get_agg_filter() is not None:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)\r\n 566 else:\r\n 567 im, l, b, trans = self.make_image(\r\n--\u003e 568 renderer, renderer.get_image_magnification())\r\n 569 if im is not None:\r\n 570 renderer.draw_image(gc, l, b, im)\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)\r\n 793 return self._make_image(\r\n 794 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,\r\n--\u003e 795 unsampled=unsampled)\r\n 796 \r\n 797 def _check_unsampled_image(self, renderer):\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)\r\n 484 # (of int or float)\r\n 485 # or an RGBA array of re-sampled input\r\n--\u003e 486 output = self.to_rgba(output, bytes=True, norm=False)\r\n 487 # output is now a correctly sized RGBA array of uint8\r\n 488 \r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/cm.py in to_rgba(self, x, alpha, bytes, norm)\r\n 254 if xx.dtype.kind == 'f':\r\n 255 if norm and xx.max() \u003e 1 or xx.min() \u003c 0:\r\n--\u003e 256 raise ValueError(\"Floating point image RGB values \"\r\n 257 \"must be in the 0..1 range.\")\r\n 258 if bytes:\r\n\r\nValueError: Floating point image RGB values must be in the 0..1 range.\r\n---------------------------------------------------------------------------\r\nValueError Traceback (most recent call last)\r\n/usr/local/lib/python3.5/dist-packages/IPython/core/formatters.py in __call__(self, obj)\r\n 339 pass\r\n 340 else:\r\n--\u003e 341 return printer(obj)\r\n 342 # Finally look for special method names\r\n 343 method = get_real_method(obj, self.print_method)\r\n\r\n/usr/local/lib/python3.5/dist-packages/IPython/core/pylabtools.py in \u003clambda\u003e(fig)\r\n 236 \r\n 237 if 'png' in formats:\r\n--\u003e 238 png_formatter.for_type(Figure, lambda fig: print_figure(fig, 'png', **kwargs))\r\n 239 if 'retina' in formats or 'png2x' in formats:\r\n 240 png_formatter.for_type(Figure, lambda fig: retina_figure(fig, **kwargs))\r\n\r\n/usr/local/lib/python3.5/dist-packages/IPython/core/pylabtools.py in print_figure(fig, fmt, bbox_inches, **kwargs)\r\n 120 \r\n 121 bytes_io = BytesIO()\r\n--\u003e 122 fig.canvas.print_figure(bytes_io, **kw)\r\n 123 data = bytes_io.getvalue()\r\n 124 if fmt == 'svg':\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)\r\n 2210 orientation=orientation,\r\n 2211 dryrun=True,\r\n-\u003e 2212 **kwargs)\r\n 2213 renderer = self.figure._cachedRenderer\r\n 2214 bbox_inches = self.figure.get_tightbbox(renderer)\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)\r\n 506 \r\n 507 def print_png(self, filename_or_obj, *args, **kwargs):\r\n--\u003e 508 FigureCanvasAgg.draw(self)\r\n 509 renderer = self.get_renderer()\r\n 510 original_dpi = renderer.dpi\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py in draw(self)\r\n 429 # if toolbar:\r\n 430 # toolbar.set_cursor(cursors.WAIT)\r\n--\u003e 431 self.figure.draw(self.renderer)\r\n 432 finally:\r\n 433 # if toolbar:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n 53 renderer.start_filter()\r\n 54 \r\n---\u003e 55 return draw(artist, renderer, *args, **kwargs)\r\n 56 finally:\r\n 57 if artist.get_agg_filter() is not None:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/figure.py in draw(self, renderer)\r\n 1473 \r\n 1474 mimage._draw_list_compositing_images(\r\n-\u003e 1475 renderer, self, artists, self.suppressComposite)\r\n 1476 \r\n 1477 renderer.close_group('figure')\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\r\n 136 if not_composite or not has_images:\r\n 137 for a in artists:\r\n--\u003e 138 a.draw(renderer)\r\n 139 else:\r\n 140 # Composite any adjacent images together\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n 53 renderer.start_filter()\r\n 54 \r\n---\u003e 55 return draw(artist, renderer, *args, **kwargs)\r\n 56 finally:\r\n 57 if artist.get_agg_filter() is not None:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/axes/_base.py in draw(self, renderer, inframe)\r\n 2579 renderer.stop_rasterizing()\r\n 2580 \r\n-\u003e 2581 mimage._draw_list_compositing_images(renderer, self, artists)\r\n 2582 \r\n 2583 renderer.close_group('axes')\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)\r\n 136 if not_composite or not has_images:\r\n 137 for a in artists:\r\n--\u003e 138 a.draw(renderer)\r\n 139 else:\r\n 140 # Composite any adjacent images together\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/artist.py in draw_wrapper(artist, renderer, *args, **kwargs)\r\n 53 renderer.start_filter()\r\n 54 \r\n---\u003e 55 return draw(artist, renderer, *args, **kwargs)\r\n 56 finally:\r\n 57 if artist.get_agg_filter() is not None:\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in draw(self, renderer, *args, **kwargs)\r\n 566 else:\r\n 567 im, l, b, trans = self.make_image(\r\n--\u003e 568 renderer, renderer.get_image_magnification())\r\n 569 if im is not None:\r\n 570 renderer.draw_image(gc, l, b, im)\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in make_image(self, renderer, magnification, unsampled)\r\n 793 return self._make_image(\r\n 794 self._A, bbox, transformed_bbox, self.axes.bbox, magnification,\r\n--\u003e 795 unsampled=unsampled)\r\n 796 \r\n 797 def _check_unsampled_image(self, renderer):\r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/image.py in _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification, unsampled, round_to_pixel_border)\r\n 484 # (of int or float)\r\n 485 # or an RGBA array of re-sampled input\r\n--\u003e 486 output = self.to_rgba(output, bytes=True, norm=False)\r\n 487 # output is now a correctly sized RGBA array of uint8\r\n 488 \r\n\r\n~/.local/lib/python3.5/site-packages/matplotlib/cm.py in to_rgba(self, x, alpha, bytes, norm)\r\n 254 if xx.dtype.kind == 'f':\r\n 255 if norm and xx.max() \u003e 1 or xx.min() \u003c 0:\r\n--\u003e 256 raise ValueError(\"Floating point image RGB values \"\r\n 257 \"must be in the 0..1 range.\")\r\n 258 if bytes:\r\n\r\nValueError: Floating point image RGB values must be in the 0..1 range.\r\n\u003cFigure size 432x288 with 1 Axes\u003e\r\n```\r\n\r\n**Expected outcome**\r\n\r\nIn matplotlib==2.0.2 and previous this code generates a image with some noise applied to it.\r\n\r\nIn matplotlib=2.1.x the error above appear.\r\n\r\n**Matplotlib version**\r\n * Operating system: ubuntu 16.04\r\n * Matplotlib version: 2.1.X\r\n * Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline\r\n * Python version: 3.5.2\r\n * Jupyter version (if applicable): Jupyterlab==0.30.6\r\n * Other libraries: \r\n \u003e numpy==1.14.0\r\n \u003e imageio==2.2.0\r\n\r\nThe libraries are installed in pure python via pip install. I also build from the source to test if a recent unreleased version had this problem solved this but also got the same output.\r\n\r\n\r\n","author":{"url":"https://github.com/cyberwillis","@type":"Person","name":"cyberwillis"},"datePublished":"2018-02-02T17:54:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/10372/matplotlib/issues/10372"}
| 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:7d345435-3b50-a15e-4d1c-6db7d1663512 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D514:26FC81:1519F9E:1C29E74:6A534A2E |
| html-safe-nonce | cbd4e181290f1986a17026be16e5b164080b962f86c326ec2fe6717513f3e766 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTE0OjI2RkM4MToxNTE5RjlFOjFDMjlFNzQ6NkE1MzRBMkUiLCJ2aXNpdG9yX2lkIjoiNzk4NTM5NTQ2NzAxMzAxNjExMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6d2f24239864238ce0cdd4868fc2085fdde1d236dd4bd1c11f2c3f1ecb60be9f |
| hovercard-subject-tag | issue:293971735 |
| 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/10372/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eef784e80ea4d774f8a0228436eec48c6748feebedf775702610611a984ec877/matplotlib/matplotlib/issues/10372 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eef784e80ea4d774f8a0228436eec48c6748feebedf775702610611a984ec877/matplotlib/matplotlib/issues/10372 |
| og:image:alt | Bug report Bug summary From matplorlib 2.0 to 2.1 this problem appeared: Floating point image RGB values must be in the 0..1 range, instead of producing an image with noise on it. Code for reproduc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cyberwillis |
| 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