Title: Hatch alpha not preserved in SVG or PDF · Issue #16883 · matplotlib/matplotlib · GitHub
Open Graph Title: Hatch alpha not preserved in SVG or PDF · Issue #16883 · matplotlib/matplotlib
X Title: Hatch alpha not preserved in SVG or PDF · Issue #16883 · matplotlib/matplotlib
Description: Bug report Bug summary A hatched patch, with hatch transparency, renders fine with the inline or PNG backends, but alpha is ignored by the SVG or PDF backends. Did not test other backends. A possible fix for SVG is simple, and included b...
Open Graph Description: Bug report Bug summary A hatched patch, with hatch transparency, renders fine with the inline or PNG backends, but alpha is ignored by the SVG or PDF backends. Did not test other backends. A possib...
X Description: Bug report Bug summary A hatched patch, with hatch transparency, renders fine with the inline or PNG backends, but alpha is ignored by the SVG or PDF backends. Did not test other backends. A possib...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/16883
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Hatch alpha not preserved in SVG or PDF","articleBody":"### Bug report\r\n\r\n**Bug summary**\r\n\r\nA hatched patch, with hatch transparency, renders fine with the inline or PNG backends, but alpha is ignored by the SVG or PDF backends. Did not test other backends.\r\n\r\nA possible fix for SVG is simple, and included below. I can open a PR with it.\r\n\r\nThis is separate from #8431 or #9894.\r\n\r\n**Code for reproduction**\r\n\r\n```python\r\nimport matplotlib.pyplot as plt\r\nfrom matplotlib.patches import Rectangle\r\n\r\nplt.rcParams['hatch.linewidth'] = 9\r\npatch = Rectangle(xy=(.1,.1), width=.5, height=.3,\r\n facecolor=\"red\",\r\n edgecolor=(0.,0.,0.,.4),\r\n hatch='/',\r\n lw=4)\r\nfig, ax = plt.subplots()\r\nax.add_patch(patch)\r\nax.set_title(\"SVG\")\r\nplt.savefig('test.svg')\r\nax.set_title(\"PDF\")\r\nplt.savefig('test.pdf')\r\nax.set_title(\"PNG\")\r\nplt.savefig('test.png')\r\n\r\n# for uploading svg and pdf output was converted to png with inkscape:\r\n# inkscape -z -e testsvg.png test.svg -d 72\r\n# inkscape -z -e testpdf.png test.pdf -d 72\r\n# and concatenated with imagemagick:\r\n# montage testsvg.png testpdf.png test.png -mode concatenate -tile 1x3 out.png\r\n```\r\n\r\n**Actual outcome**\r\n\r\n\r\n\r\nIn addition, rendering of the PDF output is inconsistent across viewers (possibly due to #3841 and further inconsistency described in #14639). Inkscape views/converts nicely (as shown) but imagemagick doesn't even render the edge opacity. Firefox also views correctly. Adobe Reader DC behaves similar to imagemagick.\r\n\r\n**Expected outcome**\r\n\r\nSVG and PDF output should look like the PNG one.\r\n\r\n**FIX**\r\n\r\nI took a look at the generated SVG. The hatch description has the following style (note the lack of `stroke-opacity`):\r\n```\r\nstyle=\"fill:#000000;stroke:#000000;stroke-linecap:butt;stroke-linejoin:miter;stroke-width:9.0;\"\r\n```\r\nThe problem lies in the `_write_hatches` method, in `backend_svg.py`, which never sets any `stroke-opacity`. A fix for SVG is as simple as adding `'stroke-opacity': str(stroke[3])` to the dict passed to the `generate_css` call.\r\n\r\n**Matplotlib version**\r\n * Operating system: Ubuntu 18.04\r\n * Matplotlib version: 3.1.2\r\n * Matplotlib backend: SVG/PDF/PNG\r\n * Python version: 3.6.8\r\n\r\nInstalled via pip.","author":{"url":"https://github.com/mnmelo","@type":"Person","name":"mnmelo"},"datePublished":"2020-03-23T16:33:06.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/16883/matplotlib/issues/16883"}
| 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:87386c31-d107-f265-c653-7e8c271cbdcd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 81F8:2B78D3:195C08A:2231F3A:6A535DDF |
| html-safe-nonce | bbf2773e2fb1fbcd73c6c8c43e820a49baef257f4cbe278597ee0d4553f0af52 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MUY4OjJCNzhEMzoxOTVDMDhBOjIyMzFGM0E6NkE1MzVEREYiLCJ2aXNpdG9yX2lkIjoiNjc1OTA4NjAxMDgzODI0NDgzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 66a9e0493b5ee0c1dab048444498239f393f2a772bf346ba29d90fef124ff669 |
| hovercard-subject-tag | issue:586343407 |
| 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/16883/issue_layout |
| twitter:image | https://opengraph.githubassets.com/90bd792b8bd867c03c26bd82a72d3b26b5c05952a7c935794a620f95fa21fd67/matplotlib/matplotlib/issues/16883 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/90bd792b8bd867c03c26bd82a72d3b26b5c05952a7c935794a620f95fa21fd67/matplotlib/matplotlib/issues/16883 |
| og:image:alt | Bug report Bug summary A hatched patch, with hatch transparency, renders fine with the inline or PNG backends, but alpha is ignored by the SVG or PDF backends. Did not test other backends. A possib... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mnmelo |
| 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