Title: Switch to requiring Pillow rather than having our own png wrapper? · Issue #15165 · matplotlib/matplotlib · GitHub
Open Graph Title: Switch to requiring Pillow rather than having our own png wrapper? · Issue #15165 · matplotlib/matplotlib
X Title: Switch to requiring Pillow rather than having our own png wrapper? · Issue #15165 · matplotlib/matplotlib
Description: It looks like Pillow's png handling (which is hand-written https://github.com/python-pillow/Pillow/blob/master/src/PIL/PngImagePlugin.py, not based on libpng) is faster than matplotlib's, both for writing and for reading: from time impor...
Open Graph Description: It looks like Pillow's png handling (which is hand-written https://github.com/python-pillow/Pillow/blob/master/src/PIL/PngImagePlugin.py, not based on libpng) is faster than matplotlib's, both for ...
X Description: It looks like Pillow's png handling (which is hand-written https://github.com/python-pillow/Pillow/blob/master/src/PIL/PngImagePlugin.py, not based on libpng) is faster than matplotlib's, b...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/15165
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Switch to requiring Pillow rather than having our own png wrapper?","articleBody":"It looks like Pillow's png handling (which is hand-written https://github.com/python-pillow/Pillow/blob/master/src/PIL/PngImagePlugin.py, not based on libpng) is faster than matplotlib's, both for writing and for reading:\r\n```python\r\nfrom time import perf_counter\r\nimport matplotlib as mpl; mpl.use(\"agg\")\r\nfrom matplotlib import pyplot as plt\r\nimport numpy as np\r\nfrom PIL import Image\r\n\r\nfig, ax = plt.subplots()\r\nfig.canvas.draw()\r\nt = np.asarray(fig.canvas.renderer._renderer)\r\nfor writer in [\"mpl\", \"pil\"]:\r\n print(f\"write with {writer}\")\r\n start = perf_counter()\r\n for _ in range(100):\r\n mpl.image.imsave(\"/tmp/test.png\", t,\r\n pil_kwargs={\"mpl\": None, \"pil\": {}}[writer])\r\n print(\"write\", perf_counter() - start)\r\n start = perf_counter()\r\n for _ in range(100):\r\n mpl.image.imread(\"/tmp/test.png\")\r\n print(\"mpl read\", perf_counter() - start)\r\n start = perf_counter()\r\n for _ in range(100):\r\n with Image.open(\"/tmp/test.png\") as image:\r\n mpl.image.pil_to_array(image)\r\n print(\"pil read\", perf_counter() - start)\r\n```\r\nyields, for me:\r\n```\r\nwrite with mpl\r\nwrite 1.5242545299988706\r\nmpl read 0.9935761439992348\r\npil read 0.46841289500298444\r\nwrite with pil\r\nwrite 1.400021340996318\r\nmpl read 0.9913013100012904\r\npil read 0.4612834110012045\r\n```\r\n\r\nhttps://github.com/matplotlib/matplotlib/issues/15160 reminded me that it's not always trivial to get C-level dependencies set up before building (though that specific issue is about freetype). We already vendor agg and qhull, and have an option to download freetype (via local_freetype/MPLLOCALFREETYPE), so the sole remaining dependency that always needs to be provided by the builder is libpng.\r\n\r\nIf we just depended (as an install_requires) on Pillow for png handling instead, we would be able to drop that dependency (together with a bunch of C code). Pillow has wheels for all three major OSes, supports PyPy, is actively developed, and has been around for a very long time.\r\n\r\nThoughts on making the switch?","author":{"url":"https://github.com/anntzer","@type":"Person","name":"anntzer"},"datePublished":"2019-08-31T20:26:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/15165/matplotlib/issues/15165"}
| 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:f47cccf7-5521-496c-68f1-5a7757ae5e48 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8030:1FCD98:8706AA:B24698:6A517EA6 |
| html-safe-nonce | 0fe342ab41bf0e81af525f7cb226bdacfff4030ee8a8be56b75c1b405120237e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDMwOjFGQ0Q5ODo4NzA2QUE6QjI0Njk4OjZBNTE3RUE2IiwidmlzaXRvcl9pZCI6IjgxODA4MDQyNDI2MTkwNzIxNjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 616caceab9f44297931c3c41ea4a67646dc6f34e739887e641e2f5ae0ff5141d |
| hovercard-subject-tag | issue:487808522 |
| 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/15165/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6b0bbc2152011f2d45bad9994e1dfd180236dea4664d57fe5f0d513f9ffe81ff/matplotlib/matplotlib/issues/15165 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6b0bbc2152011f2d45bad9994e1dfd180236dea4664d57fe5f0d513f9ffe81ff/matplotlib/matplotlib/issues/15165 |
| og:image:alt | It looks like Pillow's png handling (which is hand-written https://github.com/python-pillow/Pillow/blob/master/src/PIL/PngImagePlugin.py, not based on libpng) is faster than matplotlib's, both for ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anntzer |
| 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 | d01c62704ef24df49056c63892a149b775e1353d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width