Title: Fixed background colour of PNGs saved with a non-zero opacity. by pelson · Pull Request #1868 · matplotlib/matplotlib · GitHub
Open Graph Title: Fixed background colour of PNGs saved with a non-zero opacity. by pelson · Pull Request #1868 · matplotlib/matplotlib
X Title: Fixed background colour of PNGs saved with a non-zero opacity. by pelson · Pull Request #1868 · matplotlib/matplotlib
Description: The following code (a derivative of http://stackoverflow.com/questions/15691297/how-to-directly-set-alpha-channel-value-for-matplotlib-figure-background-colour) was producing a png with an unexpected background colour. This PR fixes the problem so that the background colour of a PNG is as expected (and consistent with SVG). import matplotlib.patches as mpatches from matplotlib.image import imread from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas from matplotlib.figure import Figure fig = Figure() canvas = FigureCanvas(fig) fig.set_facecolor('black') fig.patch.set_alpha(0.3) fig.patches.append(mpatches.CirclePolygon([200, 200], radius=80, facecolor='red')) print 'Target: ', fig.patch.get_facecolor() fig.savefig('test_fig.png', facecolor=fig.get_facecolor(), edgecolor='none') print 'Result: ', tuple(imread('test_fig.png')[0, 0]) Yields: Target: (0.0, 0.0, 0.0, 0.3) Result: (0.69803923, 0.69803923, 0.69803923, 0.3019608) After this change, the result is: Target: (0.0, 0.0, 0.0, 0.3) Result: (0.0, 0.0, 0.0, 0.3019608) I'm not certain why the value is not exact, but I'm comfortable with the approximation. There remains a problem with PDF creation (& other backends not tested). I do not propose to fix the PDF issue in this PR.
Open Graph Description: The following code (a derivative of http://stackoverflow.com/questions/15691297/how-to-directly-set-alpha-channel-value-for-matplotlib-figure-background-colour) was producing a png with an unexpect...
X Description: The following code (a derivative of http://stackoverflow.com/questions/15691297/how-to-directly-set-alpha-channel-value-for-matplotlib-figure-background-colour) was producing a png with an unexpect...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/1868
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:cf90521c-330c-7034-e04a-a196d733fc8d |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8090:1F69C6:6E07D6:953C39:6A534E54 |
| html-safe-nonce | d254fcabe0d0347a62fdf00221c4c452ba98b75f13a821ae15203b0212ce57f3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDkwOjFGNjlDNjo2RTA3RDY6OTUzQzM5OjZBNTM0RTU0IiwidmlzaXRvcl9pZCI6IjUxOTk0NjEyNzAwMjUyMTE3MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5d3d959168d6e8ade03bb423202ff5d6d20a61c7ea676b6bac9f6012dc7f5801 |
| hovercard-subject-tag | pull_request:4883159 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/matplotlib/matplotlib/pull/1868/files |
| twitter:image | https://avatars.githubusercontent.com/u/810663?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/810663?s=400&v=4 |
| og:image:alt | The following code (a derivative of http://stackoverflow.com/questions/15691297/how-to-directly-set-alpha-channel-value-for-matplotlib-figure-background-colour) was producing a png with an unexpect... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| 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